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.

Compatibility

Filter by Database
SQL NULLS ORDERING Compatibility Across Databases
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 Native 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 Native 12c
SQLite Native 3.30.0 NULLS FIRST and NULLS LAST supported in ORDER BY since SQLite 3.30.0.

Details

NULLS FIRST and NULLS LAST provide control over the handling of NULL values in sorting, which can differ across databases.

Standard Syntax

SELECT * FROM table_name ORDER BY column_name NULLS FIRST;

Version Support

MySQL: Not supported PostgreSQL: Native since 9.5 SQL Server: Not supported Oracle: Native since 12c SQLite: Native since 3.30.0

Per-Database Syntax & Notes

PostgreSQL Native syntax

SELECT * FROM table_name ORDER BY column_name NULLS FIRST;

Oracle Native syntax

SELECT * FROM table_name ORDER BY column_name NULLS FIRST;

SQLite Native syntax

NULLS FIRST and NULLS LAST supported in ORDER BY since SQLite 3.30.0.

SELECT * FROM table_name ORDER BY column_name NULLS FIRST;