BBampaa

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

Example

Finding Lowest and Highest Retail Values with MIN() and MAX()

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

Result:

lowest_pricehighest_price
18.75849.0

Step by step

  1. Run the query without MIN so you can see what the unfiltered values look like.
    SELECT price,
           MAX(price) AS highest_price
    FROM products;
  2. MIN returns the smallest value in a column.
    SELECT MIN(price),
           MAX(price) AS highest_price
    FROM products;
  3. 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

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, write a query to find the largest value in the salary column.
SELECT 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