Order By
SQL ORDER BY
The keyword ORDER BY is used to sort the records of a sql query.
Syntax
SELECT * FROM name_of_table ORDER BY name_of_column ASC;
SELECT * FROM name_of_table ORDER BY name_of_column DESC;
Example
Table of books
ID | NAME | PRICE |
---|---|---|
1 | Learn Python | 45 |
2 | MySQL Tutorial | 32 |
3 | PHP examples | 24 |
4 | Learn SQL | 32 |
SELECT name, price FROM books ORDER BY price DESC;
Output
NAME | PRICE |
---|---|
Learn Python | 45 |
MySQL Tutorial | 32 |
Learn SQL | 32 |
PHP examples | 24 |