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

What is the use of ORDER BY clause in MySQL?

WBOY
Release: 2023-09-05 20:21:08
forward
1483 people have browsed it

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)
Copy after login

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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template