Lessons › SQL › Chapter 2: Filtering
SQL lesson
IS NULL and IS NOT NULL
NULL means a cell is empty: nothing was recorded. It isn't zero, and it isn't a blank space. You can't find it with = NULL. Use IS NULL for empty cells, and IS NOT NULL for filled ones.
Try this lesson free →Example
Find empty cells
SELECT order_id, status
FROM orders
WHERE ship_date IS NULL| order_id | status |
|---|---|
| O2002 | pending |
| O2004 | processing |
Step by step
- NULL means the cell is empty: nothing was recorded.
SELECT order_id, status FROM orders WHERE ship_date IS NULL - Keeps rows where the cell is empty. = NULL doesn't work.
SELECT order_id, status FROM orders WHERE ship_date IS NULL - Keeps rows that have a value.
SELECT order_id, status FROM orders WHERE ship_date IS NULL
Practice
1. Using customers, find the customers whose email has a value.
SELECT * FROM customers WHERE email IS NOT NULL2. Using products, find the products whose brand is missing.
SELECT * FROM products WHERE brand IS NULL3. Using orders, find the orders that haven't shipped yet (no ship_date).
SELECT * FROM orders WHERE ship_date IS NULL4. Using inventory, find the products with no warehouse recorded.
SELECT * FROM inventory WHERE warehouse IS NULL5. Using reviews, show the review_id and rating of the reviews that have a rating.
SELECT review_id, rating 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 →