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_nameWHERE condition;The examples use the tables from the example database.
Smallest and largest
Section titled “Smallest and largest”The smallest production budget:
SELECT MIN(Budget) AS SmallestBudgetFROM Productions;| SmallestBudget |
|---|
| 850,000 |
The largest single invoice:
SELECT MAX(Amount) AS LargestInvoiceFROM 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.
With a condition
Section titled “With a condition”WHERE narrows the rows before the function looks at them. The lowest day rate in the accounts department:
SELECT MIN(DayRate) AS LowestRateFROM CrewWHERE Department = 'Accounts';| LowestRate |
|---|
| 300 |
Text and dates
Section titled “Text and dates”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 LatestInvoiceFROM Invoices;| LatestInvoice |
|---|
| 2025-03-12 |