max
Calculates the maximum of the non-NULL input values. The selected value keeps its original native type.
With one argument, max is an aggregate over rows. With two or more arguments, it is a scalar function comparing the arguments of one row.
Syntax
text
max(value)
max(value1, value2, ...)Arguments
value— An expression to compare across input rows. SQL value ordering and the selected collation determine the result.value1, value2, ...— Two or more values for the scalar form.
Returned value
The largest input value. The aggregate skips NULL and returns NULL for empty or all-NULL input. The scalar form returns NULL if any argument is NULL.
Examples
Finding the largest salary
sql
CREATE TABLE employees (salary INTEGER);
INSERT INTO employees VALUES (46000), (NULL), (59000), (72000);sql
SELECT max(salary)
FROM employees
FORMAT csv;text
72000Comparing native dates
sql
CREATE TABLE events (day Date);
INSERT INTO events VALUES (CAST('2025-03-10' AS Date)), (CAST('2025-01-05' AS Date));sql
SELECT max(day)
FROM events
FORMAT csv;text
"2025-03-10"Comparing values within one row
sql
SELECT max(8, 3, 12), max(8, NULL, 12)
FORMAT csv;text
12,\NRelated functions
minselects the smallest value.any_valueselects a representative non-NULLvalue.max_stateandmax_mergestore and combine intermediate extrema.