PostgreSQL 18 reference · Aggregate Functions
PostgreSQL MAX() Function
Return the largest value in a group. Works with numbers, text, dates and, since PostgreSQL 18, arrays.
PostgreSQL 18
Syntax
max(expression)
Parameters
| Parameter | Description |
|---|---|
expression |
A column or expression. |
Return value
The largest value, or NULL.
Examples
SELECT department, max(salary) AS top_salary
FROM employees
GROUP BY department
ORDER BY department;
Output
department | top_salary -------------+------------ Engineering | 210000 Management | 250000 Sales | 150000 Support | 65000 (4 rows)
Run this on your computer — see “Get Started” for setup.
SELECT max(order_date) - min(order_date) AS days_of_orders FROM orders;
Output
days_of_orders
----------------
161
(1 row)Run this on your computer — see “Get Started” for setup.
Version history
| Version | Change |
|---|---|
| PostgreSQL 18 | Accepts arrays and composite types. |
In other languages
MAX()· SQLite
Related
MIN()· Return the smallest value in a group. Works with numbers, text, dates and, since PostgreSQL 18, arrays.GREATEST()· Return the largest of a list of values, ignoring NULLs. least() returns the smallest.- SQL Aggregate Functions · tutorial
- SQL GROUP BY · tutorial