>_QueryLocalCSV & JSON tools that run in your browser

How do I find the minimum and maximum unit price per category in SQL?

SELECT category, MIN(unit_price) AS min_price, MAX(unit_price) AS max_price
FROM data
GROUP BY category
ORDER BY category;

Run this query on the demo dataset →

MIN() and MAX() can be computed in the same query, both scoped by the same GROUP BY category — SQL doesn't limit you to a single aggregate function per query, as long as every non-aggregated column in the SELECT list also appears in the GROUP BY.

A table named data with columns: order_id (integer), customer (text), country (text), category (text), quantity (integer), unit_price (real), order_date (text, YYYY-MM-DD).

Want to run it on your own file? Open it with Query CSV with SQL: your file becomes the table data, and you can paste this query with your own column names.

Related recipes