X-Original-To: pgsql-sql@postgresql.org Received: from mail6-sh.home.nl (mail6.home.nl [213.51.128.20]) by postgresql.org (Postfix) with ESMTP id E5D08475AE5 for ; Mon, 17 Mar 2003 08:34:32 -0500 (EST) Received: from cc299057a ([217.121.167.4]) by mail6-sh.home.nl (InterMail vM.5.01.05.17 201-253-122-126-117-20021021) with SMTP id <20030317133435.DDWD21331.mail6-sh.home.nl@cc299057a> for ; Mon, 17 Mar 2003 14:34:35 +0100 Message-ID: <000801c2ec89$f70eeb60$04a779d9@cc299057a> From: "J.C.M. van der Kwast" To: Subject: Howto?? Date: Mon, 17 Mar 2003 14:34:41 +0100 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0005_01C2EC92.587F3FF0" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 X-Archive-Number: 200303/405 X-Sequence-Number: 12444 This is a multi-part message in MIME format. ------=_NextPart_000_0005_01C2EC92.587F3FF0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi, After trying for a week now I've come to the conclusion that help is needed= . I've got the following problem: I have a table with id column, another id (id2) column and a value column. = For each id there can be more id2. I want id2 for id where the value is min= . I tried several things with having but it doesn't produce what I need. Ex= ample: select id, id2, min(value) from table group by id having count (*) >1 and min(value) =3D (select min(value) from table) Now it complains about id2 not being part of aggregate.=20=20 In order to get the min value I have to group by id, right? But because id2= is unique it won't do min on those values, right? So how do you tackle a p= roblem like that? Any suggestions? thanks sjors ------=_NextPart_000_0005_01C2EC92.587F3FF0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hi,
 
After trying for a week now I've come to t= he=20 conclusion that help is needed. I've got the following problem:
I have a table with id column, another id= =20 (id2) column and a value column. For each id there can be more id= 2. I=20 want id2 for id where the value is min. I tried several things with having = but=20 it doesn't produce what I need. Example:
 
select id, id2, min(value) from=20 table
group by id
having count (*) >1 and min(value)= =3D=20 (select min(value) from table)
 
Now it complains about id2 not being part = of=20 aggregate.  
In order to get the min value I have to gr= oup by=20 id, right? But because id2 is unique it won't do min on those values,= =20 right? So how do you tackle a problem like that? Any=20 suggestions?
 
thanks sjors
------=_NextPart_000_0005_01C2EC92.587F3FF0--