BBampaa

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 →
About 5–10 minutes · no sign-up needed

Example

Picking only the rows you want

SELECT * FROM orders WHERE category = 'Electronics'

Result:

order_idcategorystatusrevenue
O2001Electronicsshipped149.99
O2003Electronicsdelivered299.0

Step by step

  1. The asterisk symbol means all columns.
    SELECT *
  2. FROM tells SQL which table to pull the data from.
    SELECT *
    FROM orders
  3. WHERE keeps only the rows that match your condition.
    SELECT *
    FROM orders
    WHERE category = 'Electronics';

Practice

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

1. Using orders, find the orders where revenue is greater than 150.
SELECT * FROM orders WHERE revenue > 150
2. Using products, find the products where price is less than 50.
SELECT * FROM products WHERE price < 50
3. 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 < 50
5. 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 →
About 5–10 minutes · no sign-up needed