Specifies the ordering of NULL values in an SQL query.
Controls whether NULLs appear first or last in ORDER BY results, using NULLS FIRST or NULLS LAST. Essential for predictable sorting when NULLs are present, since NULLs sort differently across databases by default.
| Database System | Support Status | Since Version | Notes |
|---|---|---|---|
| MySQL | ✗ Not Supported | — | MySQL does not support NULLS FIRST/LAST in ORDER BY. You can use ISNULL(col) (returns 1/0) or col IS NULL in CASE to control position. |
| PostgreSQL | ✓ Supported | 9.5 | |
| SQL Server | ✗ Not Supported | — | SQL Server does not support NULLS FIRST/LAST in ORDER BY. To get a similar effect, you can use a CASE expression: ORDER BY CASE WHEN column_name IS NULL THEN 0 ELSE 1 END, column_name ASC; |
| Oracle | ✓ Supported | 12c | |
| SQLite | ✗ Not Supported | — | SQLite does not support NULLS FIRST/LAST in ORDER BY. You can use ISNULL(col) (returns 1/0) or col IS NULL in CASE to control position. |
NULLS FIRST and NULLS LAST provide control over the handling of NULL values in sorting, which can differ across databases.