X-Original-To: pgsql-sql@postgresql.org Received: from news.hub.org (news.hub.org [64.49.215.80]) by postgresql.org (Postfix) with ESMTP id D47FE475956 for ; Wed, 5 Mar 2003 21:20:29 -0500 (EST) Received: by news.hub.org (Postfix, from userid 8) id 54C8743A834; Wed, 5 Mar 2003 21:20:27 -0500 (EST) From: "Bjarke Dahl Ebert" X-Newsgroups: comp.databases.postgresql.sql References: <3E660A41.7040509@kyborg.dk> Subject: Re: problematic query (for me ;-) Lines: 36 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2720.3000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 Message-ID: <_Nx9a.112430$Hl6.10266647@news010.worldonline.dk> Date: Thu, 6 Mar 2003 02:44:47 +0100 X-Complaints-To: news-abuse@wol.dk Organization: Customer of Tiscali A/S To: pgsql-sql@postgresql.org X-Archive-Number: 200303/296 X-Sequence-Number: 12336 "Kim Petersen" wrote in message news:3E660A41.7040509@kyborg.dk... > I'm trying to get a hint as to how i can solve this problem: > > i have a table: > > n | t > ---+--- > 1 | 2 > 1 | 5 > 2 | 3 > 2 | 5 > 3 | 4 > 3 | 3 > (6 rows) > > now i want to find the pairs (n1,n2) where no t's collide - eg in this > table it would be (1,3) and (3,1). SELECT DISTINCT nt1.n, nt2.n FROM nt nt1, nt nt2 WHERE NOT EXISTS ( (SELECT t from nt where n=nt1.n) INTERSECT (SELECT t from nt where n=nt2.n)) n | n ---+--- 1 | 3 3 |1 (2 rows) I'm not sure that it scales well to large datasets... /Bjarke