This guide is specifically for MySQL syntax.
SQL Query to Filter NULL Values
Handle NULL values using IS NULL, IS NOT NULL, and COALESCE.
Quick Answer
SELECT * FROM table WHERE column IS NULL;
Explanation
NULL represents unknown/missing data. Use IS NULL/IS NOT NULL for comparison (= NULL doesn't work). COALESCE returns the first non-NULL value.
Query Variants
Is Null
SELECT * FROM employees WHERE manager_id IS NULL;
Is Not Null
SELECT * FROM employees WHERE phone IS NOT NULL;
Coalesce
SELECT name, COALESCE(phone, 'No phone') as phone FROM employees;
Nullif
SELECT name, NULLIF(status, 'inactive') as active_status FROM users;
Pro Tips
- Never use = NULL, always use IS NULL
- COALESCE handles multiple fallback values
- NULL in calculations returns NULL
Related SQL Queries
Continue learning with more SQL query examples:
MySQL-Specific Notes
This page covers MySQL syntax. Other databases may have different syntax for similar operations.