BBampaa

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 →
About 5–10 minutes · no sign-up needed

Example

The smallest and the biggest

SELECT MIN(price) AS lowest_price, MAX(price) AS highest_price
FROM products

Result:

lowest_pricehighest_price
18.75849.0

Step by step

  1. The lowest value in the column.
    SELECT MIN(price) AS lowest_price, MAX(price) AS highest_price FROM products
  2. The highest value in the column.
    SELECT MIN(price) AS lowest_price, MAX(price) AS highest_price FROM products
  3. Both in one SELECT, with a comma, gives one row.
    SELECT MIN(price) AS lowest_price, MAX(price) AS highest_price FROM products

Practice

Try each one in your head first, then open the answer.

1. Using orders, write a query to find the largest value in the revenue column.
SELECT MAX(revenue) FROM orders
2. Using store_sales, write a query to find the largest value in the revenue column.
SELECT MAX(revenue) FROM store_sales
3. Using products, write a query to find the smallest value in the price column.
SELECT MIN(price) FROM products
4. Using reviews, write a query to find the largest value in the rating column.
SELECT MAX(rating) FROM reviews
5. Using employees, find the smallest and the largest salary, as two columns.
SELECT MIN(salary), MAX(salary) FROM employees

Learn 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 →
About 5–10 minutes · no sign-up needed