The MIN()
function returns the smallest value in a column.
Syntax:
SELECT MIN(column_name) FROM table_name;
Used to find the lowest value in a numeric or date column.
The MAX()
function returns the largest value in a column.
Syntax:
SELECT MAX(column_name) FROM table_name;
Used to find the highest value in a numeric or date column.
Let’s assume we have a table employees
with columns employee_id
, name
, and salary
. We want to find the lowest and highest salaries in the company.
SELECT
MIN(salary) AS lowest_salary,
MAX(salary) AS highest_salary
FROM employees;
In this example:
MIN(salary)
retrieves the lowest salary.MAX(salary)
retrieves the highest salary.MIN()
helps find the smallest value.MAX()
helps find the largest value.The MIN()
and MAX()
functions in MySQL are essential for retrieving the smallest and largest values in a dataset. They help in data analysis, allowing users to identify minimum and maximum values efficiently.