PostgreSQL MAX

PostgreSQL MAX

The PostgreSQL MAX aggregate function returns the maximum value in a select.

MAX syntax

SELECT MAX(table_column)
FROM table_name;

MAX example

Goods table

idgood_typenamedescriptionprice
1ACar_1Car 1 description100
2ACar_2Car 2 description200
3ACar_3Car 3 description100
4BBoat_4Boat 4 description500
5BBoat_5Boat 5 description300
6CTrain_1Train 123 description800
SELECT MAX(price) 
FROM goods;

Result

800

SELECT good_type, MAX(price) max_price
FROM goods
GROUP BY good_type;

Result

good_typemax_price
B500
C800
A200