MIN() and MAX() are aggregate functions — they work across a set of rows and return a single summary value. MIN() returns the smallest value in a column, and MAX() returns the largest. They work with numbers, dates, and even text.
SELECT MIN(column_name) FROM table_name;
SELECT MAX(column_name) FROM table_name;
All examples on this page use the following products table:
| id | name | category | price | stock |
|---|---|---|---|---|
| 1 | Laptop | Electronics | 55000.00 | 12 |
| 2 | Phone | Electronics | 25000.00 | 30 |
| 3 | T-Shirt | Clothing | 800.00 | 100 |
| 4 | Headphones | Electronics | 3500.00 | 45 |
| 5 | Jeans | Clothing | 2200.00 | 60 |
| 6 | Tablet | Electronics | 35000.00 | 18 |
| 7 | Jacket | Clothing | 4500.00 | 25 |
Find the cheapest product price in the table:
SELECT MIN(price) AS lowest_price FROM products;
| lowest_price |
|---|
| 800.00 |
Find the most expensive product price:
SELECT MAX(price) AS highest_price FROM products;
| highest_price |
|---|
| 55000.00 |
You can use MIN() and MAX() together to get the full price range in one query:
SELECT
MIN(price) AS lowest_price,
MAX(price) AS highest_price,
MAX(price) - MIN(price) AS price_range
FROM products;
| lowest_price | highest_price | price_range |
|---|---|---|
| 800.00 | 55000.00 | 54200.00 |
Narrow the calculation to a specific subset of rows using WHERE:
-- Cheapest Electronics product
SELECT MIN(price) AS min_electronics
FROM products
WHERE category = 'Electronics';
-- Returns: 3500.00
-- Most expensive Clothing item
SELECT MAX(price) AS max_clothing
FROM products
WHERE category = 'Clothing';
-- Returns: 4500.00
These functions work perfectly on date columns — MIN() returns the earliest date and MAX() returns the most recent:
-- First and last order dates
SELECT
MIN(order_date) AS first_order,
MAX(order_date) AS latest_order
FROM orders;
On text columns, MIN() returns the value that comes first alphabetically and MAX() returns the last:
SELECT MIN(name) AS first_name, MAX(name) AS last_name
FROM products;
-- MIN returns: Headphones
-- MAX returns: Tablet
To get the min and max per group — for example, per category — combine with GROUP BY:
SELECT category, MIN(price) AS cheapest, MAX(price) AS most_expensive
FROM products
GROUP BY category;
| category | cheapest | most_expensive |
|---|---|---|
| Electronics | 3500.00 | 55000.00 |
| Clothing | 800.00 | 4500.00 |
MIN() and MAX() both ignore NULL values — rows where the column is NULL are simply skipped in the calculation.
MIN() returns the smallest value in a column; MAX() returns the largest.AS) to give the result a meaningful column name.WHERE to limit the calculation to specific rows.GROUP BY to get min/max values per group.NULL values automatically.