What is SQL (6)

ORDER BY Keyword

Rachel
1 min readMar 10, 2017

After selecting the data you are looking for, you may want to sort them. ORDER BY keyword is used to sort the result-set. The syntax looks like this:

SELECT column_name...
FROM table_name
ORDER BY column_name ASC|DESC, column_name ASC|DESC;

The default is to sort the records in ascending order. Therefore, if you do not necessarily need to explicit write down ‘ASC’. To sort the records in a descending order, use ‘DESC’ after ORDER BY. You can use multiple columns to sort the results.

‘US City’:

Quick Example:

SELECT City
FROM US City
ORDER BY State, City DESC;

--

--

Rachel
Rachel

Written by Rachel

Learn to fail or fail to learn

No responses yet