SQL: MIN() reference
19 March 2023 (Updated 19 March 2023)
MIN() is an aggregate function that lets you find the minimum value in a set.
Example & execution plan
select min(salary) from salaries;
SQL will execute the above query in the following steps:
- Read through the
salariestable and extract the value from the
salarycolumn for each row.
- For each value in the
salarycolumn, compare it to a running minimum value. If the current value is lower than the running minimum value, update the running minimum value to the current value.
- After running through all the rows, return the running minimum value as the result of
The data type determines the comparison algorithm
If you pass a set of
INT values to
MIN(), it will return the smallest number. If you pass it a set of
DATE values, it will return the earliest date. And so on,.