BBampaa

Lessons › SQL › Chapter 2: Filtering

SQL lesson

BETWEEN

BETWEEN returns every row where a value falls inside a range you define, endpoints included.

Try this lesson free →
About 5–10 minutes · no sign-up needed

Example

Filtering Retail Orders Within a Range Using BETWEEN

SELECT * FROM orders
WHERE revenue BETWEEN 40 AND 160

Result:

order_idcustomer_idrevenueorder_date
O2002C10245.02024-03-10
O2003C10378.992024-03-18
O2004C104150.02024-03-25
O2006C10640.02024-03-12

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 revenue BETWEEN 40 AND 160;

Practice

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

1. Using orders, write a query to find rows where revenue is between 89.0 and 299.99.
SELECT * FROM orders WHERE revenue BETWEEN 89.0 AND 299.99
2. Using products, write a query to find rows where price is between 22.5 and 299.99.
SELECT * FROM products WHERE price BETWEEN 22.5 AND 299.99
3. Using customers, find customers who signed up between '2024-01-01' and '2024-01-31'.
SELECT * FROM customers WHERE signup_date BETWEEN '2024-01-01' AND '2024-01-31'
4. Using store_sales, write a query to find rows where revenue is between 85.0 and 310.5.
SELECT * FROM store_sales WHERE revenue BETWEEN 85.0 AND 310.5
5. Using returns, write a query to find rows where refund_amount is between 50.0 and 299.99.
SELECT * FROM returns WHERE refund_amount BETWEEN 50.0 AND 299.99

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