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 →Example
Filtering Retail Orders Within a Range Using BETWEEN
SELECT * FROM orders
WHERE revenue BETWEEN 40 AND 160| order_id | customer_id | revenue | order_date |
|---|---|---|---|
| O2002 | C102 | 45.0 | 2024-03-10 |
| O2003 | C103 | 78.99 | 2024-03-18 |
| O2004 | C104 | 150.0 | 2024-03-25 |
| O2006 | C106 | 40.0 | 2024-03-12 |
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 revenue BETWEEN 40 AND 160;
Practice
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.992. 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.993. 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.55. 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.99Learn 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 →