Last updated: August 27, 2026.
GROUP BY combines rows that share the same grouping values so aggregate functions can calculate totals, counts, minimums, maximums, or averages for each group.
Syntax
SELECT group_column, aggregate_function(value_column)
FROM table_name
GROUP BY group_column;Example
SELECT Item, SUM(Price) AS total_price
FROM Antiques
GROUP BY Item
ORDER BY Item;Every selected expression should either be grouped or aggregated. Use HAVING to filter groups after aggregation and WHERE to filter rows before grouping.
See the current PostgreSQL SQL reference; confirm dialect details for your own database.