SQL SELECT MIN, MAX Statement

  • SELECT MIN returns the minimum value for a column.
  • SELECT MAX returns the maximum value for a column.
The definitive guide
for data professionals


Order today!
 See 2 min video



The SQL SELECT MIN and MAX syntax


The general MIN syntax is:
SELECT MIN(column-name)
  FROM table-name

The general MAX syntax is:
SELECT MAX(column-name)
  FROM table-name





Problem: Find the cheapest product
SELECT MIN(UnitPrice)
  FROM Product


Results:

UnitPrice
2.50




SQL SELECT MAX and MIN Examples




Problem: Find the largest order placed in 2014
SELECT MAX(TotalAmount)
  FROM [Order]
 WHERE YEAR(OrderDate) = 2014


Results:

TotalAmount
17250.00







Problem: Find the last order date in 2013
SELECT MAX(OrderDate)
  FROM [Order]
 WHERE YEAR(OrderDate) = 2013

MIN and MAX can also be used with numeric and date types.
Results:

OrderDate
2013-12-31 00:00:00.000