The SQL MIN() and MAX() Functions
The MIN() function returns the smallest value of the selected column.
The MAX() function returns the largest value of the selected column.
MIN Example
Find the lowest price:You can click on above box to edit the code and run again.
SELECT MIN(Price) FROM products ;
Output
![min price table](./images/min price.png)
MAX Example
Find the highest price:You can click on above box to edit the code and run again.
SELECT MAX(Price) FROM products ;
Output
![max price table](./images/max price.png)
MIN function Syntax:
SELECT MIN(column_name) FROM table_name WHERE condition;
MAX function Syntax:
SELECT MAX(column_name) FROM table_name WHERE condition;
Demo Products table
This product table is used for examples:
![product table](./images/product_tbl.png)
Set Column Name (Alias)
When you use MIN() or MAX() , the returned column will be named MIN(field) or MAX(field) by default. To give the column a new name, use the AS keyword: