Menu
Amazon Redshift
Database Developer Guide (API Version 2012-12-01)

MAX Function

The MAX function returns the maximum value in a set of rows. DISTINCT or ALL may be used but do not affect the result.

Syntax

Copy
MAX ( [ DISTINCT | ALL ] expression )

Arguments

expression

The target column or expression that the function operates on.

DISTINCT | ALL

With the argument DISTINCT, the function eliminates all duplicate values from the specified expression before calculating the maximum. With the argument ALL, the function retains all duplicate values from the expression for calculating the maximum. ALL is the default.

Data Types

Accepts any data type except Boolean as input. Returns the same data type as expression. The Boolean equivalent of the MIN function is the BOOL_AND Function, and the Boolean equivalent of MAX is the BOOL_OR Function.

Examples

Find the highest price paid from all sales:

Copy
select max(pricepaid) from sales; max ---------- 12624.00 (1 row)

Find the highest price paid per ticket from all sales:

Copy
select max(pricepaid/qtysold) as max_ticket_price from sales; max_ticket_price ----------------- 2500.00000000 (1 row)