The ORDER BY
keyword is used to sort the result-set in ascending or descending order.
ascending order by default
use DESC keyword to sort in descending order
SELECT * FROM Customers
ORDER BY Country;
SELECT * FROM Customers
ORDER BY Country DESC;
use several columns, for example, columnA and columnB means sort first by columnA, but if some rows have the same columnA, it orders them by columnB
SELECT * FROM Customers
ORDER BY Country, CustomerName;
The following SQL statement selects all customers from the "Customers" table, sorted ascending by the "Country" and descending by the "CustomerName" column:
SELECT * FROM Customers
ORDER BY Country ASC, CustomerName DESC;