MIN and MAX
SQL · Unit 5: Aggregates
- Full plan
- SQL
- 10 exercises
Someone calls the store before coming in: how low and how high do your prices go? MIN returns the smallest value in a column and MAX the largest.
Unlike an average, what they return is in the table. 5.25 is the price of a real product, while 201.57 wasn't the price of any.
SELECT MIN(price) AS lowest,
MAX(price) AS highest
FROM products;Returns
| lowest | highest |
|---|---|
| 5.25 | 899 |
The rest of the explanation is in the lesson, which is part of the full plan.
Exercises in this lesson
You do them in the app, which checks them on the spot and explains why.
1. Complete the code
How many units were in the biggest order the store has ever received? Fill in the blank.
2. Predict the output
There are no Cables and no Speakers left. The product with the most in stock is the Mouse, with 30. What does this query return?
3. Multiple choice
In
customers,MAX(name)returns Valerie. Valerie is the oldest customer, has the longest name in the table, and comes last in alphabetical order. Which of the three didMAXpick her for?4. Predict the output
The first order is from January 3. Today is January 15, and order 12 is dated the 20th. What does this query return?
5. Put the lines in order
The owner wants one row with three things, in this order: how many products the store sells, which one comes first in the catalog, alphabetically, and how much the most expensive one costs. Put the query in order. One line doesn't belong.
6. Predict the output
Chloë has no city on file. The table's cities are Denver, with three customers, Austin, with two, and Boston and Tampa, with one each. What does this query return?
7. Multiple choice
This query returns one row with
2026-01-03and10. What does that row say?8. Put the lines in order
How far is it from the store's lowest price to its highest? Put in order the query that gives that difference. Two lines don't belong.
9. Find the bug
The owner asks for the store's average price, with no decimals, which is 202. Someone calculated it as the midpoint between the cheapest and the most expensive, and got 452. Which line has the problem?
10. Write the code
The summary of
ordersfor the owner. Write a query with four columns: the date of the first order, then the date of the last one, then how many different days had orders, and then how many units the biggest order was for.
It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.