Lessons › SQL › Chapter 3: Summarising
SQL lesson
MIN() and MAX()
MIN() and MAX() scan every value in a column and return just the two extremes - the lowest and the highest.
Try this lesson free →Example
Finding Lowest and Highest Retail Values with MIN() and MAX()
SELECT MIN(price) AS lowest_price,
MAX(price) AS highest_price
FROM products| lowest_price | highest_price |
|---|---|
| 18.75 | 849.0 |
Step by step
- Run the query without MIN so you can see what the unfiltered values look like.
SELECT price, MAX(price) AS highest_price FROM products; - MIN returns the smallest value in a column.
SELECT MIN(price), MAX(price) AS highest_price FROM products; - AS gives the MIN result a friendly column name so the output reads cleanly.
SELECT MIN(price) AS lowest_price, MAX(price) AS highest_price FROM products;
Practice
1. Using orders, write a query to find the largest value in the revenue column.
SELECT MAX(revenue) FROM orders2. Using store_sales, write a query to find the largest value in the revenue column.
SELECT MAX(revenue) FROM store_sales3. Using products, write a query to find the smallest value in the price column.
SELECT MIN(price) FROM products4. Using reviews, write a query to find the largest value in the rating column.
SELECT MAX(rating) FROM reviews5. Using employees, write a query to find the largest value in the salary column.
SELECT MAX(salary) FROM employeesLearn 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 →