Sort and retrieve data-order by

table of Contents

 

Sort data: select column name from table name order by column name;

Sort by multiple columns: select column name 1, column name 2, column name 3 from table name order by column name 2, column name 3;

Specify the sort direction-descending order: select column name 1, column name 2 from table name order by column name 2 desc;


Sort data: select column name from table name order by column name;

 

Sort by multiple columns: select column name 1, column name 2, column name 3 from table name order by column name 2, column name 3;

In order to sort by multiple columns, just specify the column names and separate the column names with commas (just like you did when selecting multiple columns).

Sort products by prod_name only when multiple rows have the same prod_price value. If all the values ​​in the prod_price column are unique, they will not be sorted by prod_name.

 

Specify the sort direction-descending order: select column name 1, column name 2 from table name order by column name 2 desc;

Sort by multiple columns: The DESC keyword is only applied to the column name directly before it.

If you want to sort in descending order on multiple columns, you must specify the DESC keyword for each column .

Use the combination of order by and limit to find the highest or lowest value in a column.

When an ORDER BY clause is given, it should be ensured that it is located after the FROM clause. If LIMIT is used, it must be after ORDER BY.

The ORDER BY clause must be the last clause in the SELECT statement .

Guess you like

Origin blog.csdn.net/weixin_49984044/article/details/108645189