From: Stuart Rison <rison@biochemistry.ucl.ac.uk>
To: pgsql-sql <pgsql-sql@postgresql.org>
Subject: self-join and DISTINCT quandry.
Date: Wed, 29 Sep 1999 21:11:24 +0100 (BST)
Message-ID: <Pine.LNX.4.10.9909292106040.30104-100000@bsmlx17> (raw)
Dear all,
Consider the following table:
test=> select * from hum;
number|letter|family
------+------+------
1|a |one
2|b |one
3|c |one
4|d |one
5|e |one
6|f |one
7|a |two
8|b |two
9|c |two
10|g |two
11|h |two
12|i |two
(12 rows)
If I want to know what letters appear in more than one family and what
the number for number for such letters is, I could do:
test=> select t1.letter, t1.number, t2.number from hum t1, hum t2 where
t1.letter=t2.letter and t1.family<>t2.family;
letter|number|number
------+------+------
a | 1| 7
b | 2| 8
c | 3| 9
a | 7| 1
b | 8| 2
c | 9| 3
(6 rows)
test=>
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...
I'd like to do this without using DISTINCT ON if at all possible (because
I disapprove on DISTINCT ON on moral grounds ;) ).
regards,
S.
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
Subject: Re: self-join and DISTINCT quandry.
In-Reply-To: <Pine.LNX.4.10.9909292106040.30104-100000@bsmlx17>
References: <Pine.LNX.4.10.9909292106040.30104-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