X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id AD1249FA50D for ; Fri, 21 Jul 2006 06:29:25 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 32557-04 for ; Fri, 21 Jul 2006 06:29:17 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from smtp3.lc.anpe.fr (smtp3.lc.anpe.fr [80.118.163.18]) by postgresql.org (Postfix) with ESMTP id DFC8F9FA434 for ; Fri, 21 Jul 2006 06:10:04 -0300 (ADT) Received: from HOMERE01.anpe.fr (localhost.localdomain [127.0.0.1]) by smtp3.lc.anpe.fr (antivirus) with ESMTP id 635AC73CEE; Fri, 21 Jul 2006 11:10:00 +0200 (CEST) Received: from [10.0.32.170] ([10.0.32.170]) by HOMERE01.anpe.fr with Microsoft SMTPSVC(6.0.3790.1830); Fri, 21 Jul 2006 11:09:16 +0200 Message-ID: <44C099D9.5060608@anpe.fr> Date: Fri, 21 Jul 2006 11:09:45 +0200 From: Patrick Jacquot User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: marchesini@unipg.it Cc: pgsql-sql@postgresql.org Subject: Re: simple problem??? References: <1153407157.5192.64.camel@geoivan> In-Reply-To: <1153407157.5192.64.camel@geoivan> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 21 Jul 2006 09:09:16.0680 (UTC) FILETIME=[57A74880:01C6ACA5] X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=2.432 tagged_above=0 required=5 tests=SPF_HELO_SOFTFAIL X-Spam-Level: ** X-Archive-Number: 200607/271 X-Sequence-Number: 25845 ivan marchesini wrote: >Dear users.... >It's a simple problem I think (and I hope :-) > >I have a table like this: >A|B|C >1|2|20 >1|3|10 >1|4|21 >2|3|12 >2|4|22 >3|4|23 > >where the first two column are a combination without repetition (with >k=2) of the numbers 1,2,3,4 >for each pair I have a value in the column C. > >I would want a select that can extract these records: > >1|3|10 >2|3|12 >3|4|23 > > >i.e. the select must look into the A field first and: >-select all records where A=1, >-find, into this selection, the record where there's the minimum value >of the field C >-print all the fields for this record. > >then > >-select all records where A=2 >-find, into this selection, the record where there's the minimum value >of the field C >-print all the fields of this record. > >and so on... > >using >SELECT a,MIN(c) FROM table GROUP BY a > >is a partial solution because I can't see the value of B >and I obtain: > >1|10 >2|12 >3|23 > >How can I do for plotting also the value of B??? > >Thank you very much > >Ivan > > Maybe you could try Select distinct on (a,b) a,b,c from(select * from table order by A,C) The distinct on construct is a postgreSql-ism Cordialement -- Patrick