The MIN()
and MAX()
functions in MySQL let you find the smallest and largest values in a numeric column (or the earliest/latest in a date column). They’re perfect for quickly identifying extremes in your data.
MIN(column_name) MAX(column_name)
Replace column_name
with your target column (numeric or date). NULLs are ignored.
-- Smallest salary in the company SELECT MIN(salary) AS lowest_salary FROM employees; -- Earliest hire date SELECT MIN(hire_date) AS first_hired FROM employees; -- Minimum sale amount in 2024 SELECT MIN(sales_amount) AS min_sale FROM orders WHERE YEAR(order_date) = 2024;
-- Highest salary in the company SELECT MAX(salary) AS highest_salary FROM employees; -- Most recent hire date SELECT MAX(hire_date) AS last_hired FROM employees; -- Maximum sale amount in 2024 SELECT MAX(sales_amount) AS max_sale FROM orders WHERE YEAR(order_date) = 2024;
GROUP BY
-- Lowest and highest salary per department SELECT department, MIN(salary) AS dept_min_salary, MAX(salary) AS dept_max_salary FROM employees GROUP BY department;
This query shows the smallest and largest salaries in each department—great for spotting pay ranges.
WHERE
to filter before computing extremes.GROUP BY
to get min/max per category or group.Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!