SQL IS NOT NULL
The inverse of IS NULL — keeps only rows where a value actually exists.
What & Why
IS NOT NULL keeps rows where the column genuinely has a value recorded.
See How It Works
BUSINESS QUESTION
Find product feedback rows that contain an NPS score.
| 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 |
EXAMPLE QUERY
SELECT id, user_id, nps_score
FROM product.feedback
WHERE nps_score IS NOT NULL;RESULT
| id | user_id | nps_score |
|---|---|---|
| 1 | 101 | 9 |
| 3 | 103 | 7 |
Only feedback rows with a known NPS score survive IS NOT NULL.
Now You Try
Practice this concept
Product wants features that have a deprecation timestamp so the team can review retired functionality.
Available schema
productPrefix tables with product.table_name.
nameteamdeprecated_atproduct.features| Column | Type |
|---|---|
| id | integer |
| name | text |
| description | text |
| team | text |
| released_at | timestamp with time zone |
| deprecated_at | timestamp with time zone |
| internal_priority | integer |
query.sql
Sign up free to try it on a real business scenario