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

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

Syntax

max(expression)

Parameters

ParameterDescription
expression A column or expression.

Return value

The largest value, or NULL.

Examples

Largest per group
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.

A date range
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

VersionChange
PostgreSQL 18Accepts arrays and composite types.

In other languages

Was this page helpful?