Re: problematic query (for me ;-)

From: "Bjarke Dahl Ebert" <bebert(at)tiscali(dot)dk>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: problematic query (for me ;-)
Date: 2003-03-06 01:44:47
Message-ID: _Nx9a.112430$Hl6.10266647@news010.worldonline.dk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"Kim Petersen" <kp(at)kyborg(dot)dk> wrote in message
news:3E660A41(dot)7040509(at)kyborg(dot)dk(dot)(dot)(dot)
> 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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Aspire Something 2003-03-06 06:00:34 Arrays Or Loop
Previous Message James Cooper 2003-03-06 00:54:50 INTERSECT / where id IN (etc..)