Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 17A379F9DA8 for ; Mon, 20 Aug 2007 11:57:56 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 08644-05 for ; Mon, 20 Aug 2007 11:57:49 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from smtp-out01.email.it (smtp-out01.email.it [212.97.34.21]) by postgresql.org (Postfix) with ESMTP id 571529F9DA6 for ; Mon, 20 Aug 2007 11:57:55 -0300 (ADT) Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp-out01.email.it (Postfix) with ESMTP id 62287400E; Mon, 20 Aug 2007 16:57:53 +0200 (CEST) X-Virus-Scanned: amavisd-new at email.it Received: from smtp-out01.email.it ([127.0.0.1]) by localhost (smtp-out01.email.it [127.0.0.1]) (amavisd-new, port 10024) with LMTP id k4FyQjF79Kmr; Mon, 20 Aug 2007 16:57:52 +0200 (CEST) Date: Mon, 20 Aug 2007 16:57:58 +0200 To: Ben Kim From: giuseppe.derossi@email.it Cc: pgsql-admin@postgresql.org Reply-to: giuseppe.derossi@email.it Subject: Re: HELP, can't implement e filter Message-ID: <8a804b41b66f29ab046f6e43715de038@83.224.204.62> X-Priority: X-Mailer: Webmail-Email.it [Mailer version 1.70] X-SenderIP: 83.224.204.62 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="iso-8859-1" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200708/225 X-Sequence-Number: 26556 Hi guys, thanks to everybody for your help. Sorry if I was not too goot at explaining my problem, well, I have only the first table and I want to implement a filter which returns the second one. The rule to implement is: select only one c1 which has the max c2 and min c4, then display only c3,c4. and c5 in ascendig way. This is my solution, but I think I can improve it by using th Ben'suggestion : select c1,c2,c3,min(c4),min(c5) -- see min c5 works on not significat values from first_table into tab_temp group by c1,c2,c3 order by c1 select c1,max(c2),c3,c4,c5 into second_table from tab_temp group by c1,c3,c4,c5 order by c1,c4,c5 select c3,c4,c5 from second_table order by c3,c4,c5 --------- Original Message -------- Da: Ben Kim To: Cc: pgsql-admin@postgresql.org Oggetto: Re: [ADMIN] HELP, can't implement e filter Data: 20/08/07 16:15 > > > > On Sun, 19 Aug 2007, giuseppe.derossi@email.it wrote: > > > Hi, > > I need to implement a filter in order to select from the first table the > > second one... > > c1 c2 c3 c4 c5 > > 1)133659;1;"0039";"00121";7 > > 2)133664;1;"0039";"00121";12 > > 3)133664;2;"0039";"00121";12 > > 4)133665;2;"0039";"00121";12 > > 5)135460;1;"0039";"01152"; > > 6)135460;2;"0039";"01152"; > > 7)135471;1;"0050";"00153";4 > > 8)135471;2;"0050";"00153";4 > > > > 1)133659;1;"0039";"00121";7 > > 3)133664;2;"0039";"00121";12 > > 4)133665;2;"0039";"00121";12 > > 6)135460;2;"0039";"01152"; > > 8)135471;2;"0050";"00153";4 > > There should be something better but this might work. > > select * from testtable where (c1,c2) in (select c1, max(c2) from > testtable group by c1 ); > > > HTH > > Ben K. > Developer > http://benix.tamu.edu > > ---------------------------(end of broadcast)--------------------------- > TIP 3: Have you checked our extensive FAQ? > > http://www.postgresql.org/docs/faq > > > -- Email.it, the professional e-mail, gratis per te: http://www.email.it/f Sponsor: Collezioni Moda Giro d’Italia Fashion. Approfitta dei saldi estivi. Sconti dal 30 al 50%. Uomo, Donna e Bambino. Prodotto ufficiale. Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid=6908&d=20070820