Returns the minimum value in its argument. NULL values are ignored. If all inputs are NULL, MIN returns NULL.
Syntax
MIN(<expression>) [FILTER ([WHERE] <condition>)]
Parameters
| Parameter | Description | Supported input types |
|---|
<expression> | The expression whose minimum to determine | Any type |
<condition> | An optional boolean expression to filter rows used in aggregation | BOOL |
Return Types
Same as input type
Examples
The tournaments table contains the following data:
SELECT name, totalprizedollars FROM tournaments ORDER BY totalprizedollars LIMIT 5;
| name text null | totalprizedollars int null |
|---|
| The French Grand Prix | 237 |
| The European Grand Prix | 465 |
| The Desert Dash Rally | 643 |
| The Turbocharged Championship Series | 704 |
| The African Grand Prix | 895 |
Rows: 5Execution time: 6.00ms
The following example finds the smallest prize amount in the tournaments table:
SELECT MIN(totalprizedollars) AS minprize FROM tournaments;
Rows: 1Execution time: 5.74ms
MIN also works on text columns, returning the lexicographically smallest value. The following example finds the tournament name that comes first alphabetically:
SELECT MIN(name) AS mintournament FROM tournaments;
| mintournament text null |
|---|
| The Acceleration Championship |
Rows: 1Execution time: 6.22ms