NULL-handling lets you test, replace, and compare missing values so queries return the expected rows and calculations.
NULL represents "unknown." Any arithmetic or comparison with NULL becomes NULL, and equality operators never match it. Proper handling prevents wrong counts, sums, and joins.
Use IS NULL to filter rows lacking a value, and IS NOT NULL to exclude them.Writing email = NULL returns nothing because = never matches NULL.
COALESCE(expr1, …, default) returns the first non-NULL value. IFNULL(expr, default) is a MariaDB shortcut for two parameters. Both turn NULLs into useful defaults like 0 or ''.
NULLIF(a, b) returns NULL when a = b, otherwise a.Wrap divisors with NULLIF(divisor, 0) to avoid divide-by-zero errors in calculations.
ORDER BY column IS NULL, column sorts non-NULLs first regardless of ASC/DESC rules, improving report readability.
Need customer spending including pending orders? COALESCE(o.total_amount, 0) replaces NULL totals so sums don’t ignore customers with no orders.
.
Performance is usually identical for two arguments. Use COALESCE for portability and multiple arguments; IFNULL is fine for quick two-value checks.
MariaDB lacks a global setting. Use ORDER BY column IS NULL, column to place NULLs last or first as needed.
Yes. ON a.id = b.a_id never matches when either side is NULL. Use IS NULL logic or COALESCE to control join behavior.