MIN function is an aggregate function that allows you to get the minimum of values.
Consider the employee table as shown below:
You can get the minimum of all salaries as shown below:
SELECT MIN(salary) FROM employee; sum ------ 50,000
You can use MIN function along with the group by clause. Example: To return minimum of salaries per department, you can group by department as shown below:
SELECT department, MIN(salary) FROM employee GROUP BY department; department sum ---------- --- sales 50,000 accounts 55,000 support 65,000
You can filter grouped results using HAVING clause. Example: Below query returns only the departments that are paying a minimum salary of less than 60,000.
SELECT department, SUM(salary) FROM employee GROUP BY department HAVING SUM(salary)<60000; department sum ---------- --- sales 50,000 accounts 55,000