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'.
ID | Name | Quantity | Price |
---|
1 | Pen | 10 | 200 |
2 | Ink | 15 | 300 |
3 | Notebook | 20 | 400 |
4 | Pencil | 30 | 150 |
SELECT MAX(Price) AS HighPrice FROM Stationary;
The result is shown in the following table.
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'.
ID | Name | Quantity | Price |
---|
1 | Pen | 10 | 200 |
2 | Ink | 15 | 300 |
3 | Notebook | 20 | 400 |
4 | Pencil | 30 | 150 |
SELECT MIN(Price) AS LowPrice FROM Stationary;
The result is shown in the following table.