NULL (SQL)

NULL represents missing or unknown data in a database — it means 'no value here.' It is not zero and not an empty string; it is the absence of any value.

SQL

Because NULL means 'unknown', comparisons with it behave specially: NULL = NULL is not true. To test for it you must use IS NULL or IS NOT NULL, never = NULL.

Aggregate functions like SUM and AVG skip NULLs, and outer joins produce NULLs for rows that have no match on the other side.

Syntax

SELECT columns FROM table_name WHERE column IS NULL;

Examples

SQL

SELECT name
FROM users
WHERE phone IS NULL;

Output:

name
-----
Bob
Carol

Learn it in a lesson

See also

Back to the Dictionary