How to sort results
Sort ascending
ASC is the default and can be written explicitly.
SELECT title, duration_minutes
FROM courses
ORDER BY duration_minutes ASC;
Sort descending
Use DESC for the reverse direction.
SELECT title, created_at
FROM courses
ORDER BY created_at DESC;
Break ties
Add sort expressions from most important to least important for predictable results.
SELECT title, level
FROM courses
ORDER BY level ASC, title ASC;
Treat NULL deliberately
The default position of NULL differs by database. PostgreSQL supports NULLS FIRST/LAST; portable queries can sort by column IS NULL before the column.