Title - ORDER BY SQL clause Tags - sql clause programming

ORDER BY helps you display results alphabetically or numerically.

This can make the data more useful and easier to analyse.

Two rules:

  1. The column that we ORDER BY doesn’t have to be one of the columns you are displaying

  2. ORDER BY always goes after WHERE (if WHERE is present).

Example:

SELECT * FROM movies WHERE imdb_rating > 8 ORDER BY year DESC;

DESC indicates to sort the results in DESCending order (high to low or Z-A).

ASC would indicate to sort the results in ascending order (low to high or A-Z).