Difficulty: Beginner
Estimated time: 10–15 minutes
SQL concepts: NULL, IS NULL, IS NOT NULL, filtering missing data
Goal: Learn how to correctly filter rows based on missing or present values.
The Scenario
After cleaning up missing values with COALESCE, a data analyst asks:
“Can we find only the rows that still have missing values?”
In SQL, NULL behaves differently from regular values.
To filter it correctly, you must use IS NULL or IS NOT NULL.
Database Table
products
| column_name | type | description |
|---|---|---|
| product_id | INTEGER | Unique product ID |
| name | TEXT | Product name |
| category | TEXT | Product category |
| supplier_notes | TEXT | Optional notes from supplier (can be NULL) |
Sample Data
| product_id | name | category | supplier_notes |
|---|---|---|---|
| 101 | Wireless Mouse | Accessories | NULL |
| 102 | Mechanical Keyboard | Accessories | Best seller |
| 103 | 27-inch Monitor | Displays | NULL |
| 104 | USB-C Hub | Accessories | Limited stock |
| 105 | Laptop Stand | Workspace | NULL |
Your Task
Write a SQL query that returns:
- Product
name supplier_notes
…but only for products where supplier_notes is missing.
Expected Output
| name | supplier_notes |
|---|---|
| Wireless Mouse | NULL |
| 27-inch Monitor | NULL |
| Laptop Stand | NULL |
Constraints
- Use
IS NULLto filter missing values - Do not use
= NULL - Do not use
SELECT *
Hint (Optional)
In SQL:
= NULL❌ does not workIS NULL✅ is the correct way
The same applies to IS NOT NULL.
SELECT
name,
supplier_notes
FROM products
WHERE supplier_notes IS NULL;
Explanation
IS NULLchecks whether a column has no value.- Regular comparison operators (
=,!=) do not work withNULL. - This pattern is commonly used for:
- Data quality checks
- Finding incomplete records
- Debugging pipelines
Common Mistakes
- Using
= NULLWHERE supplier_notes = NULL -- ❌ always false - Forgetting NULLs behave differently
- Filtering after replacing NULLs with COALESCE
- You must filter before replacing, or use the raw column.
Try:
- Return products that do have supplier notes (
IS NOT NULL) - Count how many products are missing notes
- Combine
IS NULLwithLEFT JOINto find missing relationships
Next Challenge
Beginner Challenge #14: Filtering Ranges with BETWEEN
🔗 View reference solution on GitHub
(After you’ve tried the challenge)
Want more practical SQL challenges?
Subscribe to the Solve With SQL newsletter and get new problems delivered to your inbox.