Lessons › SQL › Chapter 2: Filtering
SQL lesson
FILTERING with WHERE
WHERE filters a table down to only the rows that meet a condition you specify, discarding everything else from the result.
Try this lesson free →Example
Picking 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
- The asterisk symbol means all columns.
SELECT * - FROM tells SQL which table to pull the data from.
SELECT * FROM orders - WHERE keeps only the rows that match your condition.
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, find the customer whose customer_id is 'C103'.
SELECT * 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 →