Brightlane's merchandising team is preparing a pricing review and needs to understand the spread of prices across the current catalogue.
Write a query to return the lowest and highest product prices in a single row.
Assumptions:
- The
productstable contains every product in Brightlane's catalogue. - The
pricecolumn is each product's unit list price.
Output:
- A single row with two columns,
min_priceandmax_price.
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
MIN(price) AS min_price,
MAX(price) AS max_price
FROM
products The shape
MIN and MAX walk the same column from opposite ends, returning the cheapest and most expensive products as two labeled columns in a single row. For Brightlane's current catalog, that's 12.99 to 1999 — a wide enough spread that the merchandising team can see the pricing range at a glance.
Clause by clause
MIN(price) AS min_pricereturns the smallestpricevalue in theproductstable. PostgreSQL scans the column, holds onto the smallest value it has seen, updates that value any time it finds a smaller one, and returns whatever it has at the end. One column, one row, one number.MAX(price) AS max_pricedoes the same thing from the opposite end — same scan, same logic, opposite extreme.- Both aggregates run against the same
FROM productssource in a single pass. The comma between them places both results in the same output row, side by side. That's exactly the shape a pricing review needs to read the spread at a glance, without running two separate queries and stitching the results. MINandMAXskipNULLvalues the same waySUMdoes. The extremes are computed over real values only; a missing price doesn't get picked as the minimum just because nothing seems smaller.
You practiced computing two boundary aggregates in one query — MIN and MAX side by side give the full range of a column in a single row. The recurring shape behind any "spread," "range," or "floor and ceiling" question.