Sorting & limiting
Concept  ·  SQL & Querying

Whether NULLs sort first or last is engine-dependent — NULLS FIRST/LAST is the explicit bar.

NULL has no ordinal value, so the standard leaves its sort position to the engine — every leaderboard, top-N, and LIMIT that can meet a NULL inherits that choice. The fix is not memorising your engine's default; it is refusing to rely on any default. NULLS LAST (or FIRST) is one token and makes the query say what you mean.

See it break
rounds
playerstrokes
Ada54
BoNULL
Cy48
Di61
The trap
SELECT
  player
FROM
  rounds
ORDER BY
  strokes ASC ;
The fix
SELECT
  player
FROM
  rounds
ORDER BY
  strokes ASC NULLS LAST;
The trap
Cy
Ada
Di
Bo
The fix
Cy
Ada
Di
Bo

The clubhouse board looks sorted, but where the rain-out NULL lands is engine-dependent — the same ORDER BY drops it first on one engine and last on another.

The rule

Declare NULLS LAST (or FIRST) so the order is explicit on every engine, or filter IS NOT NULL when absence means not-eligible.

DuckDB and Postgres default to different NULL positions; the explicit NULLS clause is the portable fix.

Shows up elsewhere
LIMIT without ORDER BYWHERE keeps only TRUE
Try one →Prove it in practice →