ORDER BY clause of SQL

Last updated: April 26, 2023

The ORDER BY clause is used to arrange/sort data ascending and descending manner. 

Syntax:

Ascending order sorting using ORDER BY clause.

SELECT column1, column2, .column3 ...
FROM table_name
ORDER BY column_name1, column_name2, column_name3 ... ASC;

OR

Descending order sorting using ORDER BY clause.

SELECT column1, column2, .column3 ...
FROM table_name
ORDER BY column_name1, column_name2, column_name3 ... DESC;

Using SQL ORDER BY ASC query:

SELECT * FROM contact ORDER BY name ASC;
Using SQL ORDER BY ASC query

Using SQL ORDER BY DESC query:

SELECT * FROM contact ORDER BY id DESC;
Using SQL ORDER BY DESC query

Using SQL ORDER BY DESC query with multiple column:

SELECT id, age, name, address FROM contact ORDER BY id DESC, age DESC;
Using SQL ORDER BY DESC query with multiple column
SELECT id, age, name, address FROM contact ORDER BY age DESC, id DESC;

Related post