How to work with NULL
Understand NULL
NULL represents missing, unknown, or inapplicable information. It is not zero, an empty string, or the text “NULL”.
Test with IS
An equality comparison cannot match NULL. Use the dedicated predicates.
SELECT name
FROM students
WHERE graduation_date IS NULL;
Replace for display
COALESCE returns the first non-NULL argument and is supported by SQLite, PostgreSQL, and MySQL.
SELECT name, COALESCE(nickname, name) AS display_name
FROM students;
Expect three-valued logic
A condition involving NULL may be unknown. A WHERE clause keeps only true rows, so test nullable values explicitly.