SQL NULL value
The marker for a missing or unknown value, and the source of most SQL surprises.
- Kategorie
- Bedingt
- Returns
no type- In this category
- 32 of 43
Syntax
x IS NULL | x IS NOT NULL
Engine-Unterstützung
| Engine | Support | Notizen |
|---|---|---|
| SQL Server | Ja | Supported under this name. |
| PostgreSQL | Ja | Supported under this name. |
| MySQL | Ja | Supported under this name. |
| SQLite | Ja | Supported under this name. |
| Oracle | Ja | Supported under this name. |
Beispiele
PostgreSQL
SELECT CASE WHEN NULL = NULL THEN 'equal' ELSE 'unknown' END AS result;
Any engine
SELECT * FROM users WHERE deleted_at IS NULL;
Gut zu wissen
- NULL = NULL is UNKNOWN; nothing equals NULL, including another NULL.
- '' and NULL are different in PostgreSQL, MySQL, SQL Server and SQLite, but Oracle treats a zero-length string AS NULL.
- Aggregates skip NULLs: AVG and SUM over an empty or all-NULL group return NULL; COUNT returns 0.
- String concatenation splits: CONCAT('a', NULL) is 'a' in PostgreSQL, SQL Server, SQLite and Oracle but NULL in MySQL; 'a' || NULL is NULL in PostgreSQL, SQLite and SQL Server 2025 but 'a' in Oracle, which treats the NULL as an empty string.
Questions about NULL
Is NULL zero or empty string?
Neither: it is 'unknown'. Zero and '' are values; NULL is the absence of one, with its own logic.
How do I test for NULL?
IS NULL and IS NOT NULL only; = NULL is always UNKNOWN.
Why does my AVG ignore rows?
AVG skips NULL values by design; use COALESCE(col, 0) if missing should count as zero.
Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.
Related on SQLly
Cheat sheets for the engines that have it: SQL Server, PostgreSQL, MySQL, SQLite, Oracle.
Functions your engine actually has
SQLly's completion lists the built-in functions of the engine you're connected to, whether that's SQL Server, PostgreSQL, MySQL, SQLite or Oracle. Hover a function for help, and signature hints show each argument as you type.