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

IDNAMEPRICE
1Learn Python45
2MySQL Tutorial32
3PHP examples24
4Learn SQL32
SELECT name, price FROM books ORDER BY price DESC;

Output

NAMEPRICE
Learn Python45
MySQL Tutorial32
Learn SQL32
PHP examples24