NULL Handling: Mistakes
Module: SQL Fundamentals
SELECT * FROM employees WHERE manager_id = NULL;
SELECT * FROM employees WHERE manager_id IS NULL;
NULL is not equal to anything, including NULL. WHERE col = NULL always returns 0 rows. This is the #1 most common SQL mistake. Always use IS NULL or IS NOT NULL.
Critical
SELECT salary + bonus AS total FROM employees;
SELECT salary + COALESCE(bonus, 0) AS total FROM employees;
NULL in calculations returns NULL. If bonus is NULL, total becomes NULL (not salary!). Use COALESCE to replace NULL with default value (0) for correct calculations.
High