Sql, order by column A and then by column B

How to write sql so that the result can be ordered first by column A than column B. Something like the following:

SELECT * FROM tbl WHERE predictor ORDER by col_A and ORDER by col_B

+54
sql select sqlite
Nov 09 '09 at 3:19
source share
3 answers
 ORDER BY col_A, col_B 

The SQLite website has syntax diagrams that explain the SQL grammar supported by SQLite.

+70
Nov 09 '09 at 3:21
source share

Just send the list of columns separated by commas to ORDER BY:

 SELECT * from table WHERE table.foo=bar ORDER BY colA, colB 

The ORDER BY clause causes the output of a string to be sorted. The ORDER BY argument is a list of expressions that are used as the key for sorting. expressions should not be part of the result for a simple SELECT, but the SELECT element for each sort expression must exactly match one of the column results. Each view expression may be optional, then the COLLATE keyword and matching name function used to organize text and / or ASC or DESC keywords to indicate sorting order.

+19
Nov 09 '09 at 3:21
source share
 SELECT * FROM tbl WHERE predictor ORDER by col_A, col_B 
+5
Nov 09 '09 at 3:22
source share



All Articles