HOME C C++ PYTHON JAVA HTML CSS JAVASCRIPT BOOTSTRAP JQUERY REACT PHP SQL AJAX JSON DATA SCIENCE AI

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:
SELECT MIN(Price) FROM products ;
You can click on above box to edit the code and run again.

Output

min price table

MAX Example

Find the  highest  price:
SELECT MAX(Price) FROM products ;
You can click on above box to edit the code and run again.

Output

max price table

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

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:

MIN Example

Find the lowest price:
SELECT MIN(Price) AS Smallest_Price FROM Products;
You can click on above box to edit the code and run again.

Output

smallest price table