MIN()
Returns the smallest value in a column across a group of rows.
Description
MIN is an aggregate function that returns the smallest value found in a
column across the rows being aggregated. It's the mirror image of MAX,
and like MAX it works on numbers, dates, and text.
Syntax
MIN(column_name)Parameters
| Name | Description | Optional |
|---|---|---|
| expression | The column or expression to evaluate. NULL values are ignored when finding the minimum. | No |
Return Type
MIN returns the same type as the column it's applied to: a numeric column
returns a number, a date or year column returns a date-like value, and so on.
Examples
Library (Books/Authors/Publishers)
Loading database engine...
Library (Books/Authors/Publishers)
Loading database engine...
MIN and MAX in the same query
You can call MIN and MAX on the same column in one SELECT to see the
full range of values at once, for example
SELECT MIN(price), MAX(price) FROM books;.
Common Mistakes
- Thinking
MINonly applies to numbers. It also works on years, dates, and text columns, returning the earliest date or the alphabetically first string. - Expecting
MINto return the whole row.MIN(price)gives you the lowest price, not the title of the book that has it. You'd need to filter or subquery for that. - Forgetting that
MINignores NULLs. If a column has missing values, they simply don't participate in the comparison, soMINwon't ever return NULL unless every value in the group is NULL.
Related Functions
See also: MAX, AVG, COUNT.