SQL Fundamentals
NULL Handling: Real-World
A customer database has optional fields: middle_name, phone, email. Queries must handle missing data correctly. Calculating total_compensation = salary + bonus
A customer database has optional fields: middle_name, phone, email. Queries must handle missing data correctly. Calculating total_compensation = salary + bonus fails when bonus is NULL (returns NULL, not salary). Reports show "N/A" instead of blank for missing values. Understanding NULL prevents silent data loss.
Unassigned support tickets
Support managers need open tickets that have not yet been assigned, while reports should display a readable fallback owner.
Explicit NULL handling keeps filtering correct without losing a useful presentation label.
Filter and display missing ownership correctly
SELECT ticket_id, COALESCE(assignee_name, 'Unassigned') AS owner FROM tickets WHERE assignee_id IS NULL AND status = 'open';
All