Received: from mail-b.bcc.ac.uk (mail-b.bcc.ac.uk [144.82.100.22]) by hub.org (8.9.3/8.9.3) with ESMTP id QAA48870 for ; Wed, 29 Sep 1999 16:06:22 -0400 (EDT) (envelope-from rison@biochemistry.ucl.ac.uk) Received: from biochem.ucl.ac.uk (actually host bsmori1.biochem.ucl.ac.uk) by mail-b.bcc.ac.uk with SMTP (XT-PP) with ESMTP; Wed, 29 Sep 1999 21:06:06 +0100 Received: from bsmlx17.biochem.ucl.ac.uk (bsmlx17 [128.40.46.142]) by biochem.ucl.ac.uk (8.9.2/8.9.1) with ESMTP id VAA18006 for ; Wed, 29 Sep 1999 21:06:12 +0100 (BST) Received: from localhost (rison@localhost) by bsmlx17.biochem.ucl.ac.uk (8.9.3/8.6.6) with ESMTP id VAA32746 for ; Wed, 29 Sep 1999 21:11:24 +0100 X-Authentication-Warning: bsmlx17.biochem.ucl.ac.uk: rison owned process doing -bs Date: Wed, 29 Sep 1999 21:11:24 +0100 (BST) From: Stuart Rison X-Sender: rison@bsmlx17 To: pgsql-sql Subject: self-join and DISTINCT quandry. Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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