From: Knut P Lehre <k.p.lehre@world-online.no>
To: pgsql-sql@postgresql.org
Subject: select
Date: Sat, 7 Aug 2004 13:54:28 +0200
Message-ID: <40FEE9C6000006B4@cpfe9.be.tisc.dk> (raw)
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.
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: k.p.lehre@world-online.no
Subject: Re: select
In-Reply-To: <40FEE9C6000006B4@cpfe9.be.tisc.dk>
* 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