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
Syntax
max(X) | max(X, Y, ...)
Parameters
| Parameter | Description |
|---|---|
X |
A column or expression. |
Return value
The largest value, or NULL.
Examples
SELECT department, max(salary) AS top_salary
FROM employees
GROUP BY department;
Output
department | top_salary Engineering | 210000 Management | 250000 Sales | 150000 Support | 65000
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
GREATEST()· PostgreSQLMAX()· PostgreSQL
Related
MIN()· With one argument, return the smallest value in a group. With two or more, return the smallest of the arguments.- SQL Aggregate Functions · tutorial
- SQL GROUP BY · tutorial