ORDER BY
Anonymous contributor
Anonymous contributor1 total contribution
Anonymous contributor
Published Jun 4, 2021Updated Oct 6, 2023
Contribute to Docs
The ORDER BY
command sorts the result set by a particular column either alphabetically or numerically.
Syntax
SELECT column_name
FROM table_name
ORDER BY column_name ASC | DESC;
It’s also possible to ORDER BY
multiple columns by separating them with a comma.
SELECT column_name_1
FROM table_name
ORDER BY column_name_1 ASC | DESC, column_name_2 ASC | DESC;
This assumes column_name_1
and column_name_2
exist in table_name
.
ORDER BY
can be set in two ways:
ASC
is a keyword used to sort the results in ascending order (default).DESC
is a keyword used to sort the results in descending order.
Example
The query below will sort by birth_date
, in descending order:
SELECT *FROM contactsORDER BY birth_date DESC;
All contributors
- Anonymous contributorAnonymous contributor1 total contribution
- BrandonDusch580 total contributions
- christian.dinh2476 total contributions
- Anonymous contributorAnonymous contributor3071 total contributions
- Anonymous contributor
- BrandonDusch
- christian.dinh
- Anonymous contributor
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.