sql group by statement

From: "Albrecht Berger" <berger1517(at)gmx(dot)ch>
To: "pgsql" <pgsql-sql(at)postgresql(dot)org>
Subject: sql group by statement
Date: 2002-09-13 10:29:21
Message-ID: 002f01c25b10$6db4b940$a07ba8c0@wxp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hello,
I have a problem, which I'm not able to solve with a simple query :

I need a resultset with distinct id's, but the max val2 of each id.
I tried to group by id, but though I need the pk in my resultset
I have to group it too, which "destroys" the group of val2.

Can this be done without a huge query ?

Table :
pk id val1 val2
1 1 2 3
2 1 2 4
3 2 1 1
4 1 0 5
5 2 1 8

Needed Result :
pk id val1 val2
4 1 0 5
5 2 1 8


Thx
berger

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message dima 2002-09-13 10:33:59 Re: sql group by statement
Previous Message Jrg 2002-09-13 09:07:57 How can unique columns being case-insensitive be accomplished?