X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 0657F5E3AC5 for ; Sat, 7 Aug 2004 08:54:38 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 93120-01 for ; Sat, 7 Aug 2004 11:54:29 +0000 (GMT) Received: from smtp130.tiscali.dk (smtp130.tiscali.dk [62.79.79.112]) by svr1.postgresql.org (Postfix) with ESMTP id 1A68A5E37CF for ; Sat, 7 Aug 2004 08:54:26 -0300 (ADT) Received: from cpmail.dk.tiscali.com (mail.tiscali.dk [212.54.64.159]) by smtp130.tiscali.dk (8.12.11/8.12.11) with ESMTP id i77BsTZq040609 for ; Sat, 7 Aug 2004 13:54:29 +0200 (CEST) (envelope-from k.p.lehre@world-online.no) Received: from [129.240.242.30] by cpmail.dk.tiscali.com with HTTP; Sat, 7 Aug 2004 13:54:28 +0200 Date: Sat, 7 Aug 2004 13:54:28 +0200 Message-ID: <40FEE9C6000006B4@cpfe9.be.tisc.dk> From: "Knut P Lehre" Subject: select Reply-To: k.p.lehre@basalmed.uio.no To: pgsql-sql@postgresql.org MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=2.4 tagged_above=0.0 required=5.0 tests=HOT_NASTY, RCVD_IN_BL_SPAMCOP_NET, RCVD_IN_SORBS X-Spam-Level: ** X-Archive-Number: 200408/54 X-Sequence-Number: 18551 I have a table with fields: id A B C D E F where id is an int4 primary key. In this table there is information like: 1 a1 b1 xxx xxx 2 a1 b1 xxx xxx xxx xxx 3 a2 b2 xxx xxx xxx xxx 4 a2 b2 xxx xxx xxx xxx 5 a3 b3 xxx xxx xxx 6 a3 b3 xxx xxx xxx xxx 7 a3 b3 xxx xxx xxx xxx 8 a4 b4 xxx xxx xxx xxx 9 a1 b1 xxx 10 a3 b3 xxx 11 a1 b3 xxx where xxx represents any information. My problem is: I only want to select one of the records which have the same combination of information in fields A and B, and that should be the record with the lowest id. Thus, the resultset should be: 1 a1 b1 xxx xxx 3 a2 b2 xxx xxx xxx xxx 5 a3 b3 xxx xxx xxx 8 a4 b4 xxx xxx xxx xxx 11 a1 b3 xxx Importantly, I might not want the selected records listed in order of increasing id. They might be sorted according to the data in e.g. the C field. Suggestions/comments greatly appreciated.