sajad torkamani

MIN() is an aggregate function that lets you find the minimum value in a set.

Syntax

MIN(expression)

Example & execution plan

select min(salary) from salaries;

SQL will execute the above query in the following steps:

  1. Read through the salaries table and extract the value from the salary column for each row.
  2. For each value in the salary column, 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.
  3. After running through all the rows, return the running minimum value as the result of MIN().

Other notes

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,.

Sources

Tagged: MySQL