Select*fromratelist;+----+------+-------+|Sr |Item|Price|+----+------+-------+|1|A|502||2|B|630||3|C|1005||4| h|850||5|T|250|+----+------+-------+5rowsinset"/> Select*fromratelist;+----+------+-------+|Sr |Item|Price|+----+------+-------+|1|A|502||2|B|630||3|C|1005||4| h|850||5|T|250|+----+------+-------+5rowsinset">

Home  >  Article  >  Database  >  What is the use of ORDER BY clause in MySQL?

What is the use of ORDER BY clause in MySQL?

WBOY
WBOYforward
2023-09-05 20:21:081428browse

MySQL中ORDER BY子句有什么用?

MySQL The ORDER BY clause is used to specify the ordering of query results. The keyword ORDER BY must be followed by the name of the column we want to sort on. For example, we want to sort the following table named "ratelist" based on the "price" column -

mysql> Select * from ratelist;
+----+------+-------+
| Sr | Item | Price |
+----+------+-------+
| 1  | A    |  502  |
| 2  | B    |  630  |
| 3  | C    | 1005  |
| 4  | h    |  850  |
| 5  | T    |  250  | 
+----+------+-------+
5 rows in set (0.05 sec)

You can use the ORDER BY clause to complete sorting, as shown below -

mysql> Select * from ratelist ORDER BY Price;
+----+------+-------+
| Sr | Item | Price |
+----+------+-------+
| 5  | T    |  250  |
| 1  | A    |  502  |
| 2  | B    |  630  |
| 4  | h    |  850  |
| 3  | C    | 1005  | 
+----+------+-------+
5 rows in set (0.01 sec)

The above query sorts the table based on price in the default sort order (i.e. ascending order).

The above is the detailed content of What is the use of ORDER BY clause in MySQL?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete