ORDER BY sorts ascending by default; add DESC for highest first. Sort by several columns to break ties, for example ORDER BY revenue DESC, name.
Without ORDER BY, SQL does not promise any row order, even if the output looks sorted.
Worked example
What are the three most expensive products?
SELECT name, price FROM products ORDER BY price DESC LIMIT 3;
| name | price |
|---|---|
| 14-inch laptop | 1199 |
| Mini PC | 549 |
| Standing desk | 499 |
Common mistakes
- Using LIMIT without ORDER BY and getting an arbitrary "top" list.
- Forgetting a tie-breaker, so equal values come back in a different order each time.