SQL Topic
NULL Handling
NULL is 'unknown', not a value: it never equals anything, never matches a join, and sorts first in ascending order. Interviewers test NULL awareness with COALESCE, IS NULL, NOT IN traps, and aggregate behavior.
When is NULL Handling used?
Any question with optional columns: referees, bonuses, salaries, foreign keys that may be missing.
Core syntax
COALESCE(col, default), col IS NULL / col IS NOT NULL, and remember NOT IN with NULLs returns nothing.Common mistakes
- Comparing with = NULL instead of IS NULL.
- Using NOT IN when the subquery can return NULL.
- Forgetting that aggregates skip NULLs, changing COUNT and AVG results.
Practice NULL Handling questions
Work through them in order — each question builds on the last.