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.
Saved automatically
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.
Related Questions in SQL & Relational Databases
What are Clustered and Non-Clustered Indexes in SQL, and when should you use each?
Intermediate level • 443 views
Explain Redis In-Memory Data Structures and Common Caching Patterns (Cache-Aside, Write-Through, Write-Behind).
Intermediate level • 63 views
How do INNER JOIN and LEFT JOIN differ when a customer has no orders?
Easy level • 58 views
A LEFT JOIN report counts one order for customers who have none. What caused it?
Medium level • 57 views
Explain SQL ACID properties and the differences between READ COMMITTED and REPEATABLE READ isolation levels.
Intermediate level • 55 views