NULL: the value that is not a value

Step 1 of 110%

Concept · step 1 of 11

What NULL is

NULL means unknown or missing. It is not zero and not an empty string: it is the absence of a value, and SQL reasons about it with three truth values instead of two.

  • Comparisons give unknown. 7 = NULL is not false, it is NULL, and so is NULL = NULL.
  • WHERE keeps only true. a row whose condition is unknown is left out, exactly like one that is false.
  • Ask with IS. phone IS NULL is true or false, never unknown.
SELECT name FROM customers WHERE phone IS NULL;
Linus has no phone on the board. NULL also spreads: 'tel: ' || phone is NULL when the phone is, and so is most arithmetic. Every step in this lesson is a place where that one NULL changes the answer, and where it surprises people who have written SQL for years.
PostgreSQL docs: Comparison operators and IS DISTINCT FROM ↗

Starting a real database in your browser

It is called PostgreSQL. The first time it downloads about 5 MB; after that it is kept, and starts faster.

PostgreSQL running in your browser