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 • 388 views
Explain SQL ACID properties and the differences between READ COMMITTED and REPEATABLE READ isolation levels.
Intermediate level • 3 views
What is Database Indexing, how does a B+ Tree index work, and when should you avoid creating indexes?
Intermediate level • 2 views
Explain Database Normalization from 1NF through BCNF with real-world anomaly examples.
Intermediate level • 2 views
Explain Redis In-Memory Data Structures and Common Caching Patterns (Cache-Aside, Write-Through, Write-Behind).
Intermediate level • 2 views