Lessons › SQL › Chapter 2: Filtering
SQL lesson
IN
IN checks whether a value matches anything in a list you provide, collapsing a chain of OR conditions into a single, readable filter.
Try this lesson free →Example
Filtering Retail Products with IN
SELECT * FROM products
WHERE category IN ('Electronics', 'Beauty', 'Footwear')| product_id | product_name | brand | category | price |
|---|---|---|---|---|
| P2001 | Wireless Mouse | NovaTech | Electronics | 29.99 |
| P2003 | Face Cleanser | GlowUp | Beauty | 18.5 |
| P2004 | Running Shoes | FitGear | Footwear | 119.99 |
| P2006 | Lip Balm Set | GlowUp | Beauty | 14.99 |
Step by step
- The asterisk symbol means all columns.
SELECT * - FROM tells SQL which table to pull the data from.
SELECT * FROM products - WHERE keeps only the rows that match your condition.
SELECT * FROM products WHERE category IN ('Electronics', 'Beauty', 'Footwear');
Practice
1. Using orders, write a query to find rows where customer_id is one of: 'C101', 'C102'.
SELECT * FROM orders WHERE customer_id IN ('C101', 'C102')2. Using products, write a query to find rows where product_id is one of: 'P2001', 'P2002'.
SELECT * FROM products WHERE product_id IN ('P2001', 'P2002')3. Using customers, write a query to find rows where email is one of: 'alice.chen@shopmail.com', 'bob.tanaka@retail.net'.
SELECT * FROM customers WHERE email IN ('alice.chen@shopmail.com', 'bob.tanaka@retail.net')4. Using store_sales, write a query to find rows where sale_id is one of: 'S9001', 'S9002'.
SELECT * FROM store_sales WHERE sale_id IN ('S9001', 'S9002')5. Using returns, write a query to find rows where return_id is one of: 'R5001', 'R5002'.
SELECT * FROM returns WHERE return_id IN ('R5001', 'R5002')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 →