pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Albrecht Berger <berger1517@gmx.ch>
To: pgsql <pgsql-sql@postgresql.org>
Subject: sql group by statement
Date: Fri, 13 Sep 2002 12:29:21 +0200
Message-ID: <002f01c25b10$6db4b940$a07ba8c0@wxp> (raw)

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





view thread (6+ messages)  latest in thread

Message-ID: <002f01c25b10$6db4b940$a07ba8c0@wxp>
Permalink:  ../002f01c25b10$6db4b940$a07ba8c0@wxp/
Also on:    postgresql.org/message-id/002f01c25b10$6db4b940$a07ba8c0@wxp

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: berger1517@gmx.ch
  Subject: Re: sql group by statement
  In-Reply-To: <002f01c25b10$6db4b940$a07ba8c0@wxp>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox