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.
MIN() function returns the smallest value of the selected column of a table.
SELECT MIN(columnName)
FROM tableName
WHERE [CONDITION];
MAX() function returns the largest value of the selected column of a table.
SELECT MAX(columnName)
FROM tableName
WHERE [CONDITION];
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 |
Finding the lowest salary from the table "Employee", a query will be:
SELECT MIN(Salary) AS LowestSalary
FROM Employee;
| LowestSalary |
| 15000 |
Finding the highest salary from the table "Employee", a query will be:
SELECT MAX(Salary) AS HighestSalary
FROM Employee;
| HighestSalary |
| 76000 |