SQL MAX() and MIN() Functions

SQL MAX() Function

The SQL MAX() function returns the largest value of the selected column of a table.

Syntax:
SELECT MAX(Column_name) FROM table_name;

Example : Query using MAX() Function.
Consider the following table titled as 'Stationary', which contains the information of products.

Write a query to display a highest price from table 'Stationary'.

IDNameQuantityPrice
1Pen10200
2Ink15300
3Notebook20400
4Pencil30150

SELECT MAX(Price) AS HighPrice FROM Stationary;

The result is shown in the following table.

HighPrice
400

SQL MIN() Function

The SQL MIN() function returns the smallest value of the selected column of a table.

Syntax:
SELECT MIN(Column_name) FROM table_name;

Example : Query using MIN() Function.
Consider the following table titled as 'Stationary', which contains the information of products.

Write a query to display a Low price from table 'Stationary'.

IDNameQuantityPrice
1Pen10200
2Ink15300
3Notebook20400
4Pencil30150

SELECT MIN(Price) AS LowPrice FROM Stationary;

The result is shown in the following table.

LowPrice
150