Re: [SQL] self-join and DISTINCT quandry. - Mailing list pgsql-sql

From Stuart Rison
Subject Re: [SQL] self-join and DISTINCT quandry.
Date
Msg-id Pine.LNX.4.10.9909301105550.690-100000@bsmlx17
Whole thread Raw
In response to Re: [SQL] self-join and DISTINCT quandry.  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-sql
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



pgsql-sql by date:

Previous
From: Safa Pilavcı
Date:
Subject: CONTAINS keyword
Next
From: "Safa Pilavcý"
Date:
Subject: Fw: CONTAINS keyword