Understanding NULL Values in SQL: Mistakes
Module: Foundational Concepts
WHERE column = NULL
WHERE column IS NULL
NULL comparisons always return UNKNOWN. Only IS NULL / IS NOT NULL work.
Never use = NULL or != NULL. Always use IS NULL / IS NOT NULL
High
Returns 0 rows because NULL = NULL is UNKNOWN
salary + bonus (when bonus is NULL)
salary + COALESCE(bonus, 0)
NULL propagates. Any arithmetic with NULL returns NULL.
Use COALESCE to treat NULL as 0 in calculations
High
If bonus is NULL, entire result is NULL
Using COUNT(*) when you mean COUNT(column)
COUNT(*) includes NULLs, COUNT(column) excludes NULLs
COUNT(*) = total rows. COUNT(column) = non-NULL values.
Choose based on what you need: all rows or non-NULL values
Medium
COUNT(*) counts all rows, COUNT(column) counts non-NULL values