The NULLS modifier is used in an ORDER BY clause to explicitly position NULL values either at the beginning (NULLS FIRST) or the end (NULLS LAST) of the sorted result set. Without this clause, SQL engines apply their own defaults: in ascending order, most databases treat NULL as the lowest possible value, while in descending order they treat NULL as the highest. NULLS FIRST and NULLS LAST give developers deterministic, cross-dialect control over null placement, which is essential for accurate ranking, reporting, and pagination. The feature became part of the SQL:2003 standard, but support varies: PostgreSQL, Oracle, BigQuery, Redshift, Snowflake, and modern SQLite versions honor it, whereas MySQL and SQL Server do not. When unsupported, similar behavior can be emulated with expressions such as ORDER BY column IS NULL, column.
- sort_column
(column or expression) - The value used to order rows.- ASC | DESC
(keyword) - Optional direction of the sort. Default is ASC.- NULLS FIRST | NULLS LAST
(keyword) - Chooses where NULLs appear in the order.ORDER BY, ASC, DESC, NULL, COALESCE, IS NULL, IS NOT NULL
SQL:2003
In ascending order, most engines place NULLs first. In descending order, they place NULLs last. Always check your database documentation because defaults vary.
Use a boolean expression in ORDER BY: ORDER BY column IS NULL, column; This orders by whether the value is NULL (false before true) and then by the actual column.
Yes. Specify NULLS FIRST/LAST for each key independently: ORDER BY priority DESC NULLS LAST, created_at NULLS FIRST;
No. It only affects row ordering. Aggregate functions like COUNT or SUM still ignore NULLs unless stated otherwise.