Skip to main content
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

ParameterDescriptionSupported input types
<expression>The expression whose maximum to determineAny type
<condition>An optional boolean expression to filter rows used in aggregationBOOL

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 nulltotalprizedollars int null
The Drifting Thunderdome24768
The Talladega Thrill24747
The Elite Speed Demons Cup24346
The Volcanic Venture Rally24323
The Drifting Wasteland24271

Rows: 5Execution time: 6.00ms

The following example finds the largest prize amount in the tournaments table:
SELECT MAX(totalprizedollars) AS maxprize FROM tournaments;
maxprize int null
24768

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