BBampaa

Lessons › SQL › Deep Dive: Data Validation

SQL lesson

Unexpected category checks

Unexpected category checks find values in your data that don't appear on an approved reference list.

Try this lesson free →
About 5–10 minutes · no sign-up needed

Example

Checking Retail Products for Unexpected Categories

SELECT product_id, category, brand
FROM products
WHERE category NOT IN ('Electronics', 'Clothing', 'Home', 'Beauty', 'Grocery', 'Fashion')
   OR category IS NULL

Result:

product_idcategorybrand
P1004GadgetsTechPlus
P1005BeautyBliss

Step by step

  1. After SELECT, list the column names you want, separated by commas.
    SELECT product_id, category, brand
  2. FROM tells SQL which table to pull the data from.
    SELECT product_id, category, brand
    FROM products
  3. WHERE keeps only the rows that match your condition.
    SELECT product_id, category, brand
    FROM products
    WHERE category NOT IN ('Electronics', 'Clothing', 'Home', 'Beauty', 'Grocery', 'Fashion')
       OR category IS NULL;

Practice

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

1. Using orders, write a query that finds rows where order_id is NOT in the expected set ('Active', 'Inactive', 'Pending').
SELECT * FROM orders WHERE order_id NOT IN ('Active', 'Inactive', 'Pending')
2. Using customers, write a query that finds rows where email is NOT in the expected set ('Active', 'Inactive', 'Pending').
SELECT * FROM customers WHERE email NOT IN ('Active', 'Inactive', 'Pending')
3. Using products, write a query that finds rows where category is NOT in the expected set ('Active', 'Inactive', 'Pending').
SELECT * FROM products WHERE category NOT IN ('Active', 'Inactive', 'Pending')
4. Using store_sales, write a query that finds rows where channel is NOT in the expected set ('Active', 'Inactive', 'Pending').
SELECT * FROM store_sales WHERE channel NOT IN ('Active', 'Inactive', 'Pending')
5. Using employees, write a query that finds rows where full_name is NOT in the expected set ('Active', 'Inactive', 'Pending').
SELECT * FROM employees WHERE full_name NOT IN ('Active', 'Inactive', 'Pending')

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