MIN and MAX Functions
What you'll learn: You'll discover how to quickly find the smallest and largest values in any database column using SQL's MIN and MAX aggregate functions.
What Are MIN and MAX?
MIN and MAX are aggregate functions that scan an entire column and return a single result: the minimum (smallest) or maximum (largest) value found. Think of them like flipping through a stack of numbered cards to find either the lowest or highest number — except the database does it instantly across thousands or millions of rows.
These functions work with numeric data (prices, ages, scores), dates (earliest or most recent), and even text (alphabetically first or last).
Basic Syntax
SELECT MIN(column_name) FROM table_name;
SELECT MAX(column_name) FROM table_name;
Practical Examples
Find the cheapest product:
SELECT MIN(price) FROM products;
Find the most expensive product:
SELECT MAX(price) FROM products;
Find the earliest order date:
SELECT MIN(order_date) FROM orders;
Find the highest employee salary:
SELECT MAX(salary) FROM employees;
Combining with Other Columns
You can use MIN and MAX alongside other aggregates:
SELECT MIN(price), MAX(price), AVG(price)
FROM products;
This returns the lowest price, highest price, and average price all in one query.
Important Notes
MINandMAXignoreNULLvalues automatically- They return
NULLif the column contains onlyNULLvalues - They work across the entire result set (or within groups if combined with
GROUP BY, which you'll learn later)
Key Takeaway: Use MIN() to find the smallest value and MAX() to find the largest value in any column — they're essential tools for quickly understanding the range of your data.