BBampaa

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

Example

Finding Missing Retail Order Values with IS NULL and IS NOT NULL

SELECT order_id, status
FROM orders
WHERE ship_date IS NULL

Result:

order_idstatus
O2002pending
O2004processing

Step by step

  1. After SELECT, list the column names you want, separated by commas.
    SELECT order_id, status
  2. FROM tells SQL which table to pull the data from.
    SELECT order_id, status
    FROM orders
  3. WHERE keeps only the rows that match your condition.
    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, write a query to find rows where email has a value.
SELECT * FROM customers WHERE email IS NOT NULL
2. Using products, write a query to find rows where brand is missing.
SELECT * FROM products WHERE brand IS NULL
3. Using orders, write a query to find rows where order_id has a value.
SELECT * FROM orders WHERE order_id IS NOT NULL
4. Using inventory, write a query to find rows where warehouse is missing.
SELECT * FROM inventory WHERE warehouse IS NULL
5. Using reviews, write a query to find rows where rating has a value.
SELECT * 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