BBampaa

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 →
About 5–10 minutes · no sign-up needed

Example

Find empty cells

SELECT order_id, status
FROM orders
WHERE ship_date IS NULL

Result:

order_idstatus
O2002pending
O2004processing

Step by step

  1. NULL means the cell is empty: nothing was recorded.
    SELECT order_id, status FROM orders WHERE ship_date IS NULL
  2. Keeps rows where the cell is empty. = NULL doesn't work.
    SELECT order_id, status FROM orders WHERE ship_date IS NULL
  3. Keeps rows that have a value.
    SELECT order_id, status FROM orders WHERE ship_date IS NULL

Practice

Try each one in your head first, then open the answer.

1. Using customers, find the customers whose email has a value.
SELECT * FROM customers WHERE email IS NOT NULL
2. Using products, find the products whose brand is missing.
SELECT * FROM products WHERE brand IS NULL
3. Using orders, find the orders that haven't shipped yet (no ship_date).
SELECT * FROM orders WHERE ship_date IS NULL
4. Using inventory, find the products with no warehouse recorded.
SELECT * FROM inventory WHERE warehouse IS NULL
5. 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 NULL

Learn 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 →
About 5–10 minutes · no sign-up needed