1. Sort by single column
Select Column name from table name order by column name;
2. Sort by multiple columns
Select Column Name 1, column name 2, column name 3 from table name order BY column name 1, column name 2;
NOTE: If column name 1 has multiple duplicates, it will not be sorted by column name 2, only column name 1 is unique and will be sorted by column name 2.
3. Sort By Column position
Select Column Name 1, column name 2, column name 3 from table name order by 2, 3;
Note: Column name 1, column name 2, column name 3 are marked clearly in order to make the order by 2 and 3 execute correctly.
4. Specify the sort direction
The Order by column name is followed by DESC, which is performed in descending order.
The Order by column name is followed by no DESC, the default is ascending, and if you do ascending, the order by followed by ASC does not affect.
Select Column Name 1, column name 2, column name 3 from table name order BY column name 1 desc;
Specifies that a column is executed in descending order
Select Column Name 1, column name 2, column name 3 from table name order BY column name 1 desc, column name 2, column name 3;
This article is from the "Poplar" blog, please make sure to keep this source http://dabaiyang.blog.51cto.com/3537462/1941638
Sort the results of a search