Note: SQL is not case sensitive. ORDER BY is equivalent to order by. Example, select all data stored in the "Persons" table and sort the results according to the "Age" column:
output: Glenn Quagmire 33 Peter Griffin 35 1, sorting in ascending or descending order If you use the ORDER BY keyword, the sort order of the recordset is ascending by default (1 before 9, "a" before "p"). Please use the DESC keyword to set descending order (9 comes before 1, "p" comes before "a"):
2, sort based on two columns You can sort based on multiple columns. When sorting by multiple columns, the second column is used only if the first column is the same:
|