Lessons › SQL › Chapter 2: Filtering
SQL lesson
IS NULL and IS NOT NULL
IS NULL and IS NOT NULL find rows where a value is either completely absent or actually filled in - because "nothing" isn't a value you can compare with equals, any more than you can weigh an empty box on a scale designed for objects.
Try this lesson free →Example
Finding Missing Retail Order Values with IS NULL and IS NOT NULL
SELECT order_id, status
FROM orders
WHERE ship_date IS NULL| order_id | status |
|---|---|
| O2002 | pending |
| O2004 | processing |
Step by step
- After SELECT, list the column names you want, separated by commas.
SELECT order_id, status - FROM tells SQL which table to pull the data from.
SELECT order_id, status FROM orders - WHERE keeps only the rows that match your condition.
SELECT order_id, status FROM orders WHERE ship_date IS NULL;
Practice
1. Using customers, write a query to find rows where email has a value.
SELECT * FROM customers WHERE email IS NOT NULL2. Using products, write a query to find rows where brand is missing.
SELECT * FROM products WHERE brand IS NULL3. Using orders, write a query to find rows where order_id has a value.
SELECT * FROM orders WHERE order_id IS NOT NULL4. Using inventory, write a query to find rows where warehouse is missing.
SELECT * FROM inventory WHERE warehouse IS NULL5. Using reviews, write a query to find rows where rating has a value.
SELECT * FROM reviews WHERE rating IS NOT NULLLearn it by doing. This lesson is a short hands-on level on Bampaa: see it work, then build and write it yourself, with instant feedback.
Try this lesson free →