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 →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| product_id | category | brand |
|---|---|---|
| P1004 | Gadgets | TechPlus |
| P1005 | BeautyBliss |
Step by step
- After SELECT, list the column names you want, separated by commas.
SELECT product_id, category, brand - FROM tells SQL which table to pull the data from.
SELECT product_id, category, brand FROM products - 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
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 →