From: Stuart Rison <rison@biochemistry.ucl.ac.uk>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-sql <pgsql-sql@postgreSQL.org>
Subject: Re: [SQL] self-join and DISTINCT quandry.
Date: Thu, 30 Sep 1999 11:08:35 +0100 (BST)
Message-ID: <Pine.LNX.4.10.9909301105550.690-100000@bsmlx17> (raw)
In-Reply-To: <5276.938647349@sss.pgh.pa.us>
Dear Tom,
Thanks a lot, that works great, the simple ideas are always the best!
There is one proviso. If the two numbers are equal, the 'hack' does not
work. So the trick, as you point out, is to distinguish on oid's (... AND
t1.oid<t2.oid) since these are by definition unique.
regards,
S.
On Wed, 29 Sep 1999, Tom Lane wrote:
> Stuart Rison <rison@biochemistry.ucl.ac.uk> writes:
> > But what is I didn't want the information to appear twice. I could try
> > adding DISTINCT but that would not work because row a,1,7 is of course
> > DISTINCT from a,7,1 although I am looking for such duplication to be
> > eliminated...
>
> Bit of a hack, but you could add the condition
> ... AND t1.number < t2.number;
> to get rid of the two-way duplication that otherwise arises from
> your join. (Any other way of selecting just one of the pair
> of matches would work as well, of course; you could compare the
> two row's OIDs if nothing else was handy.)
>
> Not sure if you still need DISTINCT after that.
>
> regards, tom lane
>
> ************
>
Stuart C. G. Rison
Department of Biochemistry and Molecular Biology
6th floor, Darwin Building, University College London (UCL)
Gower Street, London, WC1E 6BT, United Kingdom
Tel. 0207 504 2303, Fax. 0207 380 7033
e-mail: rison@biochem.ucl.ac.uk
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: rison@biochemistry.ucl.ac.uk, tgl@sss.pgh.pa.us
Subject: Re: [SQL] self-join and DISTINCT quandry.
In-Reply-To: <Pine.LNX.4.10.9909301105550.690-100000@bsmlx17>
References: <5276.938647349@sss.pgh.pa.us> <Pine.LNX.4.10.9909301105550.690-100000@bsmlx17>
* 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