SQL NULL in Comparisons
Every comparison operator — =, <>, <, >, <=, >= — returns UNKNOWN whenever either side is NULL, with zero exceptions.
What & Why
This rule has no exceptions: any standard comparison operator involving NULL on either side evaluates to UNKNOWN, not TRUE or FALSE. This applies identically to =, <>, <, >, <=, and >=.
See How It Works
BUSINESS QUESTION
Product wants to inspect the TRUE, FALSE, or UNKNOWN result of nps_score >= 8 on every feedback row.
| 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 the comparison return TRUE, FALSE, or UNKNOWNExample 1 of 4
nps_score >= 8
| id | nps_score | comparison_result |
|---|---|---|
| 1 | 9 | TRUE |
| 2 | NULL | ? |
| 3 | 7 | ? |
| 4 | NULL | ? |
The known score 9 satisfies nps_score >= 8.
EXAMPLE QUERY
SELECT
id,
nps_score,
nps_score >= 8 AS comparison_result
FROM product.feedback
ORDER BY id;Now You Try
Practice this concept
Product inspects the TRUE, FALSE, or UNKNOWN result of nps_score >= 8 for every feedback row.
Available schema
productPrefix tables with product.table_name.
idnps_scorecomparison_resultproduct.feedback| Column | Type |
|---|---|
| id | integer |
| user_id | integer |
| feature_id | integer |
| rating | integer |
| nps_score | integer |
| comment | text |
| created_at | timestamp with time zone |
| moderation_bucket | text |
query.sql
Sign up free to try it on a real business scenario