SQL Basics | DML: Data Manipulation Language | ORDER BY

The ORDER BY keyword is used to sort a result set in ascending or descending order.

By default, ORDER BY sorts records in ascending order. To sort records in descending order, use the DESC keyword.

ORDER BY syntax

SELECT column_name1, column_name2, ...
FROM table_name
ORDER BY column_name1, column_name2, ... ASC|DESC;

ORDER BY examples

Example 1

SELECT * FROM customers
ORDER BY country;

Example 2

SELECT * FROM customers
ORDER BY country, customer_name;

Example 3

SELECT * FROM customers
ORDER BY country ASC, customer_name DESC;