Facebook Page Twitter Page LinkedIn Page
× SQL Tutorial SQL Advanced SQL Database SQL Resources


The SQL MIN() function returns the minimum value of a selected column of a table. Similarly, the SQL MAX() function returns the maximum value of a selected column of a table.

Syntax

The syntax for using MIN() and MAX() functions are given below:

/* SQL MIN() Function */
SELECT MIN(column_name) 
FROM table_name
WHERE condition(s);

/* SQL MAX() Function */
SELECT MAX(column_name) 
FROM table_name
WHERE condition(s);

Example:

Consider a database table called Employee with the following records:

EmpIDNameCityAgeSalary
1JohnLondon253000
2MarryNew York242750
3JoParis272800
4KimAmsterdam303100
5RameshNew Delhi283000
6HuangBeijing282800

  • To fetch minimum Salary of the employees present in the Employee table, the SQL code is:

    SELECT MIN(Salary) AS MinSalary 
    FROM Employee;
    

    This will produce the result as shown below:

    MinSalary
    2750
  • To fetch maximum Salary of the employees present in the Employee table, the SQL code is:

    SELECT MAX(Salary) AS MaxSalary 
    FROM Employee;
    

    This result of the following code will be:

    MaxSalary
    3100
  • To fetch minimum Salary of the employees group by their age and age greater than 27 , the SQL code is:

    SELECT Age, MIN(Salary) AS MinSalary 
    FROM Employee
    WHERE Age > 27
    GROUP BY Age;
    

    This result of the above code will be:

    AgeMinSalary
    282800
    303100