Lessons › SQL › Chapter 3: Summarising
SQL lesson
MIN() and MAX()
MIN gives the smallest value in a column. MAX gives the biggest. Put both in one SELECT with a comma, and you get them side by side in one row.
Try this lesson free →Example
The smallest and the biggest
SELECT MIN(price) AS lowest_price, MAX(price) AS highest_price
FROM products| lowest_price | highest_price |
|---|---|
| 18.75 | 849.0 |
Step by step
- The lowest value in the column.
SELECT MIN(price) AS lowest_price, MAX(price) AS highest_price FROM products - The highest value in the column.
SELECT MIN(price) AS lowest_price, MAX(price) AS highest_price FROM products - Both in one SELECT, with a comma, gives one row.
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, find the smallest and the largest salary, as two columns.
SELECT MIN(salary), 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 →