AI engineering glossary · SQL databases
What is ORDER BY?
ORDER BY: The clause that sorts a query's result by one or more columns or expressions, ascending by default or descending with DESC. Without it, row order is not guaranteed and may change between runs.
ORDER BY: an example
ORDER BY amount DESC, order_date ASC lists biggest orders first, breaking ties with the earliest date.
Related terms
More SQL databases terms
- Parameterised query
- PARTITION BY
- Phantom read
- PostgreSQL
- Primary key
- Query optimizer
- RANK and DENSE_RANK
- Recursive CTE
Where you learn it
ORDER BY is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.