Lesson 12 / 37 · Ordering and limits

Where NULL sorts is up to you

NULL has no place on a number line, so every database picks a rule: DuckDB puts NULLs last either way, PostgreSQL puts them first in a descending sort. Write NULLS FIRST or NULLS LAST and the result no longer depends on the database.

The query

SELECT name, signup_date
FROM customers
ORDER BY signup_date DESC NULLS LAST

Try NULLS FIRST: Ines moves to the top.

Next: LIMIT without ORDER BY is a coin flip · All lessons