Syntax
Parameters
| Parameter | Description | Supported input types |
|---|---|---|
<result> | The column from which the value is returned | Any type |
<value> | The column that is minimized | Any type |
<condition> | An optional boolean expression to filter rows used in aggregation | BOOL |
Return Types
Same as input type of<result>
Example
This example uses the following table,tournaments:
| name | totalprizedollars |
|---|---|
| The Drift Championship | 22,048 |
| The Lost Track Showdown | 5,336 |
| The Acceleration Championship | 19,274 |
| The French Grand Prix | 237 |
| The Circuit Championship | 9,739 |
MIN_BY is used to find the name of the tournament with the lowest total prize:
'd' or 'e', as rows 2, 4, and 5 minimize the second argument, but the first argument is NULL for row 2. Because non-NULL values of the first argument exist for the other rows, one of those values is returned. Which of them is non-deterministic, hence this query may return either 'd' or 'e'.
Example
However, if all rows minimizing the second argument are NULL in the first argument, NULL is returned:
NULL.