Home › Learn › SQL › Shaping results

NULL

Lesson 9 of 26. Missing values and how to test for them.

NULL means "no value": unknown, not applicable, not entered. It is not zero and not an empty string, and it compares equal to nothing, not even itself: city = NULL is never true. The test is city IS NULL and its opposite city IS NOT NULL.

NULLs also drop out of arithmetic (price + NULL is NULL) and are skipped by aggregate functions such as AVG, which is usually what you want and occasionally a trap. One customer in the practice data has no city.

SELECT name FROM employees WHERE manager_id IS NULL;

Your task

Show the name of the customers whose city is not recorded.

Hint 1

city IS NULL, not city = NULL.

Show the solution
SELECT name FROM customers WHERE city IS NULL;

    Runs SQLite compiled to WebAssembly in this tab; the database is rebuilt before every run.