Hostgre


HomeReferenceSQLSQL MAX() and MIN() Functions

SQL MAX() and MIN() Functions

The MAX() function finds the largest value of the selected column. The MIN() function finds the smallest value of the selected column.

MAX() Syntax

SELECT MAX(column_name) FROM table_name WHERE condition;

MIN() Syntax

SELECT MIN(column_name) FROM table_name WHERE condition;
 

Demonstration

Here is a selection from the "Products" table in the sample database:
ProductIDProductNameSupplierIDCategoryIDUnitPrice
1Whey Protein1112 boxes x 22 bags20
2BCAA1126 - 14 oz bottles21
3Sugar Syrup1214 - 500 ml bottles12
4Energy Drink2250 - 8 oz jars24
5GourmetMix2238 boxes23.35
 

MAX() Example

The following SQL statement search the price of the most expensive product:

Example

SELECT MAX(Price) AS LargestPrice FROM Products;

MIN() Example

The following SQL statement search the price of the cheapest product:

Example

SELECT MIN(Price) AS SmallestPrice FROM Products;