A Brightlane buyer is reviewing the mid-range product catalogue for a quarterly selection meeting. The range of interest covers all items priced between $50 and $200, inclusive of both endpoints.
Write a query to return the name and price of every qualifying product.
Assumptions:
- The
productstable contains every product in Brightlane's catalogue. - A product priced exactly at
$50or exactly at$200qualifies — both endpoints are included.
Output:
- One row per qualifying product, with columns
nameandprice.
Schema · ecommerce 5 tables
Run previews · Check grades
Write a query, then run it to see results here.
Worked solution Try it yourself first
SELECT
name,
price
FROM
products
WHERE
price BETWEEN 50 AND 200 The shape
BETWEEN 50 AND 200 is the compact form of a two-sided range check, and both endpoints are included by definition — exactly what the buyer's mid-range cut needs.
Clause by clause
SELECT name, pricereturns the two columns the selection meeting needs: the product label and the price the buyer is evaluating against. Every other column inproductsis dropped.FROM productsreads the catalogue.WHERE price BETWEEN 50 AND 200keeps only the rows whosepriceis at least50and at most200. The endpoint values land in the result —Gift Card $50at50and any product at200would both qualify — becauseBETWEENis inclusive on both sides.
Why this and not price >= 50 AND price <= 200
The two forms are exactly equivalent — same rows, every time. BETWEEN is the shorthand; the longer form is what it compiles to.
Reach for BETWEEN when the question is naturally "in this range, inclusive." Reach for the longer form when the bounds aren't symmetric — price >= 50 AND price < 200, with the upper bound exclusive. BETWEEN can't express that asymmetry.
You practiced using BETWEEN for an inclusive range filter. price BETWEEN 50 AND 200 is exactly equivalent to price >= 50 AND price <= 200 — the more compact form when the question is naturally "in this range, inclusive."