SQL Min and Max

The MIN and MAX functions return the smallest and largest values in a column, making them handy for finding extremes like the cheapest product or the latest date.

Finding the extremes

MIN() returns the lowest value found in a chosen column, and MAX() returns the highest. They work on numbers as you would expect, but they also work on text and dates: for text the order is alphabetical, and for dates the earliest date is the minimum while the most recent is the maximum.

Lowest and highest salary

SELECT MIN(salary) AS lowest_salary
FROM Employees;

SELECT MAX(salary) AS highest_salary
FROM Employees;

Naming the result column

Without a column alias, many databases label the output with the raw expression, such as MIN(salary). Adding AS gives the result a clean, readable name, which is especially helpful when a report shows several aggregates side by side.

Both extremes in one query

SELECT MIN(salary) AS lowest_salary,
       MAX(salary) AS highest_salary
FROM Employees;
Note: MIN and MAX skip NULL values. If every value in the column is NULL, both functions return NULL rather than an error.

Using MIN and MAX with GROUP BY

Combining these functions with GROUP BY lets you find the extreme value within each category. The query below reports the highest salary paid inside every department instead of across the whole company.

Top salary in each department

SELECT department, MAX(salary) AS top_salary
FROM Employees
GROUP BY department;
FunctionNumeric dataText dataDate data
MIN()Smallest numberFirst alphabeticallyEarliest date
MAX()Largest numberLast alphabeticallyMost recent date
Note: MIN and MAX return only the extreme value, not the row it belongs to. To also see the employee name attached to that value, you typically need a subquery or an ORDER BY with a row limit.