Skip to content

SQL MIN() and MAX() Functions

MIN() returns the smallest value in a column and MAX() the largest. Each reads every row the query selects and gives back a single value.

SELECT MIN(column_name)
FROM table_name
WHERE condition;

The examples use the tables from the example database.

The smallest production budget:

SELECT MIN(Budget) AS SmallestBudget
FROM Productions;
SmallestBudget
850,000

The largest single invoice:

SELECT MAX(Amount) AS LargestInvoice
FROM Invoices;
LargestInvoice
41,250.00

AS gives the result column a readable name; without it, the column would be headed something like MAX(Amount). SQL Aliases covers this in more detail.

WHERE narrows the rows before the function looks at them. The lowest day rate in the accounts department:

SELECT MIN(DayRate) AS LowestRate
FROM Crew
WHERE Department = 'Accounts';
LowestRate
300

MIN() and MAX() are not only for numbers. On text they give the first and last value in alphabetical order, and on dates the earliest and latest. The most recent invoice date:

SELECT MAX(InvoiceDate) AS LatestInvoice
FROM Invoices;
LatestInvoice
2025-03-12