Returns the maximum value in its argument. NULL values are ignored. If all inputs are NULL, MAX returns NULL.
Syntax
MAX(<expression>) [FILTER ([WHERE] <condition>)]
Parameters
| Parameter | Description | Supported input types |
|---|
<expression> | The expression whose maximum 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 DESC LIMIT 5;
| name text null | totalprizedollars int null |
|---|
| The Drifting Thunderdome | 24768 |
| The Talladega Thrill | 24747 |
| The Elite Speed Demons Cup | 24346 |
| The Volcanic Venture Rally | 24323 |
| The Drifting Wasteland | 24271 |
Rows: 5Execution time: 6.00ms
The following example finds the largest prize amount in the tournaments table:
SELECT MAX(totalprizedollars) AS maxprize FROM tournaments;
Rows: 1Execution time: 5.86ms
MAX also works on text columns, returning the lexicographically largest value. The following example finds the tournament name that comes last alphabetically:
SELECT MAX(name) AS maxtournament FROM tournaments;
| maxtournament text null |
|---|
| The Winter Wilderness Rally |
Rows: 1Execution time: 5.94ms