SQL IS NULL
The only correct way to check for a missing value — = NULL never works, no matter how tempting it looks.
What & Why
NULL means "no value recorded" — not zero, not an empty string, genuinely absent. IS NULL is the only way to test for it; ordinary comparisons like = NULL never return true, not even when comparing a NULL to itself.
See How It Works
BUSINESS QUESTION
Find product feedback rows where nps_score is missing.
| id | user_id | feature_id | rating | nps_score | comment | created_at |
|---|---|---|---|---|---|---|
| 1 | 101 | 1 | 5 | 9 | Clear and useful | 2024-01-25 12:15:00+00 |
| 2 | 102 | 2 | 4 | NULL | Export worked well | 2024-02-20 15:40:00+00 |
| 3 | 103 | 1 | 4 | 7 | Helpful setup flow | 2024-03-18 09:05:00+00 |
| 4 | 104 | 3 | 3 | NULL | Needs clearer timing | 2024-04-08 17:30:00+00 |
Watch is null check each rowRow 1 of 4
-- checking 1: 9 IS NULL?FALSE — dropped| id | nps_score |
|---|---|
| 1 | 9 |
| 2 | NULL |
| 3 | 7 |
| 4 | NULL |
nps_score IS NULL is false for 1.
EXAMPLE QUERY
SELECT id, user_id, rating
FROM product.feedback
WHERE nps_score IS NULL;Now You Try
Practice this concept
Marketing wants leads that have not converted yet.
Available schema
marketingPrefix tables with marketing.table_name.
idemailconverted_atmarketing.leads| Column | Type |
|---|---|
| id | integer |
| campaign_id | integer |
| text | |
| created_at | timestamp with time zone |
| qualified_at | timestamp with time zone |
| converted_at | timestamp with time zone |
| lead_score | integer |
| source | text |
| country | text |
| archive_status | text |
query.sql
Sign up free to try it on a real business scenario