Lessons › SQL › Chapter 2: Filtering
SQL lesson
FILTERING with WHERE
WHERE keeps only the rows that match a rule, like category = 'Electronics'. The rest are left out. The rule is a column, a comparison and a value. Text goes in single quotes. Numbers don't.
Try this lesson free →Example
Keep only the rows you want
SELECT *
FROM orders
WHERE category = 'Electronics'| order_id | category | status | revenue |
|---|---|---|---|
| O2001 | Electronics | shipped | 149.99 |
| O2003 | Electronics | delivered | 299.0 |
Step by step
- Keeps only the rows that match. The rest are left out.
SELECT * FROM orders WHERE category = 'Electronics' - A column, a comparison, then the value to match.
SELECT * FROM orders WHERE category = 'Electronics' - Text goes in single quotes. Numbers don't: revenue > 100.
SELECT * FROM orders WHERE category = 'Electronics'
Practice
1. Using orders, find the orders where revenue is greater than 150.
SELECT * FROM orders WHERE revenue > 1502. Using products, find the products where price is less than 50.
SELECT * FROM products WHERE price < 503. Using orders, find the orders where category is 'Clothing'.
SELECT * FROM orders WHERE category = 'Clothing'4. Using inventory, find the rows where stock_count is less than 50.
SELECT * FROM inventory WHERE stock_count < 505. Using customers, show the full_name and email of the customer whose customer_id is 'C103'.
SELECT full_name, email FROM customers WHERE customer_id = 'C103'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 →