SQLite 3 reference · Aggregate Functions

SQLite MAX() Function

With one argument, return the largest value in a group. With two or more, return the largest of the arguments.

SQLite 3

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

max(X)  |  max(X, Y, ...)

Parameters

ParameterDescription
X A column or expression.

Return value

The largest value, or NULL.

Examples

Largest per groupTry it yourself
SELECT department, max(salary) AS top_salary
FROM employees
GROUP BY department;

Output

department | top_salary
Engineering | 210000
Management | 250000
Sales | 150000
Support | 65000
As a scalar functionTry it yourself
SELECT name, price, max(price - 10, 0) AS after_10_off
FROM products
WHERE product_id IN (8, 11);

Output

name | price | after_10_off
Coffee Mug | 12 | 2
Rubber Duck | 5.5 | 0

In SQLite, a query with exactly one min() or max() aggregate can also select other columns, and they come from the row holding that extreme value. Other databases reject such queries, so join or use a window function for portable SQL.

In other languages

Was this page helpful?