;

SQL MIN and MAX


SQL has many built-in functions to perform a calculation in SQL. In this tutorial, we will learn how to use MAX() and MIN() functions using SQL.

SQL MIN() and MAX() Functions

MIN() Function:

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

Syntax - MIN() Function
SELECT MIN(columnName)
FROM tableName
WHERE [CONDITION];

MAX() Function:

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

Syntax - MAX() Function
SELECT MAX(columnName)
FROM tableName
WHERE [CONDITION];

Example:

Let us consider this table "Employee" for records.

Table Name: Employee

ID EmpName City Country Gender Salary
1 Shankar Delhi India male 25000
2 Sourabh Delhi India male 30000
3 Ranvijay Mumbai India male 15000
4 Kapil Noida India male 25000
5 Shalini Jaipur India female 18000
6 Rakesh Faridabad India male 23000
7 Akshay Mumbai India male 21000
8 Sarah New York US female 76000
9 Rocky Noida India male 28000

Example of MIN() Function

Finding the lowest salary from the table "Employee", a query will be:

Example - MIN() Function
SELECT MIN(Salary) AS LowestSalary
FROM Employee;
Output
LowestSalary
15000

Example of MAX() Function

Finding the highest salary from the table "Employee", a query will be:

Example - MAX() Function
SELECT MAX(Salary) AS HighestSalary
FROM Employee;
Syntax - SELECT Statement
HighestSalary
76000