SQL MIN and MAX Functions
beginneraggregation
2 min read
What are MIN and MAX?
MIN returns the smallest value in a column. MAX returns the largest. They work on numbers, dates, and strings.
Syntax
SELECT MIN(column), MAX(column) FROM table_name;When to Use
- Finding the cheapest and most expensive product
- Getting the earliest and latest order dates
- Identifying extremes in your data
Key Points
- Works on Multiple Types — Numbers, dates, and strings (alphabetical order).
- NULLs Ignored — MIN and MAX skip NULL values.
- With GROUP BY — Find min/max per category.
- Single Row Result — Without GROUP BY, MIN and MAX return a single row.
- Index Optimization — MIN and MAX on indexed columns are very fast.
Guided Practice
Solve the challenge below. Use hints when stuck and check your answer for instant feedback.
Practice challengeGuided learning mode
SQL MIN and MAX Functions Challenge
Write a query that find the cheapest and most expensive product prices.
Expected result
Two values: the lowest and highest prices in the products table.
Hidden checks
- Returned rows and values
- Output columns and result shape
- Final database state after the query runs
Lesson guidance
What are MIN and MAX?
Initializing database...Each run starts from fresh sample data.
More Examples
Youngest and oldest student
Find the age range of students.
Initializing database...Each run starts from fresh sample data.
Frequently Asked Questions
Does MIN work with dates?
Yes. MIN on a date column returns the earliest date, and MAX returns the latest date.
How do I get the row with the minimum value?
Use ORDER BY column ASC LIMIT 1, or a subquery: SELECT * FROM products WHERE price = (SELECT MIN(price) FROM products);