Learn SQL Lesson

Missing Values with NULL

Real data often has missing or unknown values. SQL represents those values with `NULL`.

`NULL` is not the same as an empty string, zero, or the word "unknown". It means the value is absent.

This matters because normal comparisons do not work the way beginners often expect:

WHERE department = NULL

That does not find missing departments. To test for missing values, use `IS NULL`:

WHERE department IS NULL

To find rows where a value is present, use `IS NOT NULL`.

You will see `NULL` again in later lessons. A `LEFT JOIN` uses `NULL` when there is no matching row. Aggregates like `SUM` and `AVG` usually ignore `NULL` values. Advanced subtotal queries can also use `NULL` to mark totals.

Open interactive editor