Sorting with ORDER BY
By default, SQL doesn't guarantee any particular order for results. Use ORDER BY to sort them.
Basic ORDER BY
SELECT * FROM users ORDER BY column_name;
By default, ORDER BY sorts in ascending order (A-Z, 0-9, oldest-newest).
Ascending and Descending
-- Ascending (default)
SELECT * FROM users ORDER BY age ASC;
-- Descending
SELECT * FROM users ORDER BY age DESC;
Exercises
Loading exercise...
Loading exercise...
Loading exercise...
Loading exercise...
Combining WHERE and ORDER BY
ORDER BY always comes after WHERE:
SELECT * FROM users WHERE condition ORDER BY column;
Loading exercise...
Free Practice
Loading SQL editor...
Experiment with:
- Sorting by different columns
- Combining filtering and sorting
- Comparing ASC vs DESC results

