This is a query that selects the set of required rows:
select max(a), b, c, d, e
from T
group by b, c, d, e;
The table has a primary key in the column id.
I would like to identify these rows in the next query, getting the primary key from each of these rows. How should I do it? This does not work:
select id, max(a), b, c, d, e
from T
group by b, c, d, e;
ERROR: column "T.id" must appear in the GROUP BY clause or be used in an aggregate function
I tried this from the fact that I poked around some other postgresql questions, but no luck:
select distinct on (id) id, max(a), b, c, d, e
from T
group by b, c, d, e;
ERROR: column "T.id" must appear in the GROUP BY clause or be used in an aggregate function
What should I do? I know that for each result there can be only one id, call its primary key ... I literally want the primary key along with the rest of the data for each row to return the original (working) request.