ORDER BY

Sorts the result set by a particular column either alphabetically or numerically.

Syntax

ORDER BY can be ordered in two ways:

  • DESC is a keyword used to sort the results in descending order.
  • ASC is a keyword used to sort the results in ascending order (default).
SELECT column_name
FROM table_name
ORDER BY column_name ASC | DESC;

Example

The below query will sort the result set by the birth_date column in descending order.

SELECT *
FROM contacts
ORDER BY birth_date DESC;
Edit this page on GitHub

Contributors

Interested in helping build Docs? Read the Contribution Guide or share your feedback.

Learn SQL on Codecademy

Edit this page on GitHub

Contributors