Verified Jobs Live
SQL & Relational Databases Easy Level ~3 min read

How should SQL queries test for NULL, and why is NULL = NULL not true?

Interactive Practice Mode
Formulate your thoughts or take notes before revealing the model solution.
Model Answer & Deep-Dive Explanation

NULL represents missing or unknown information, and ordinary comparisons involving NULL evaluate to unknown rather than true or false. Use IS NULL or IS NOT NULL to test for it. WHERE keeps only rows whose condition is true, so an unknown comparison does not pass. COUNT(column) excludes NULL values while COUNT(*) counts rows. Be cautious with NOT IN when its input can contain NULL; a correlated NOT EXISTS often expresses the intended exclusion more safely. Database-specific null-safe equality operators exist but should be chosen explicitly.