Skip to main content
Returns the value of the first argument for the row that contains the maximum of the second argument. If the maximum of the second argument is not unique, an arbitrary non-NULL value of the first argument is returned from the set of rows that maximize the second argument. If the first argument is NULL for all rows maximizing the second argument, NULL is returned.

Syntax

Parameters

Return Types

Same as input type of <result>

Examples

The tournaments table contains the following data:

Rows: 5Execution time: 6.00ms

The following example finds the tournament name with the highest prize amount in the tournaments table:

Rows: 1Execution time: 6.87ms

When multiple rows maximize the second argument, an arbitrary non-NULL value of the first argument is chosen. The result of the following query is non-deterministic — either 'd' or 'e' may be returned, as both maximize value while having a non-NULL key:

Rows: 1Execution time: 6.04ms

If all rows maximizing the second argument have NULL in the first argument, NULL is returned:

Rows: 1Execution time: 6.51ms