What is NULL in SQL and how do you handle it?

Answer

NULL in SQL represents missing, unknown, or inapplicable data — it is NOT zero, empty string, or false. NULL is a special marker meaning "no value." Three-valued logic: any comparison involving NULL produces UNKNOWN (not TRUE or FALSE). This means WHERE column = NULL never returns rows — you must use IS NULL or IS NOT NULL. Arithmetic with NULL always returns NULL: 5 + NULL = NULL, NULL * 0 = NULL. Handling NULLs: IFNULL(expr, fallback) — returns fallback if expr is NULL: IFNULL(phone, "N/A"); COALESCE(a, b, c, ...) — returns the first non-NULL value from the list (standard SQL, more flexible than IFNULL); NULLIF(a, b) — returns NULL if a equals b, otherwise returns a (useful to prevent division by zero: total / NULLIF(count, 0)). Aggregate functions (SUM, AVG, MAX, MIN, COUNT(column)) ignore NULLs. COUNT(*) counts all rows including NULLs; COUNT(column) counts only non-NULL values in that column. Design: only allow NULL when truly meaning "unknown" — prefer NOT NULL with default values where possible.