Skip site navigation (1) Skip section navigation (2)

Re: self join

From: Seb <spluque(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: self join
Date: 2011-05-14 22:49:15
Message-ID: 87tycwsxsk.fsf@kolob.subpolar.dyndns.org (view raw or flat)
Thread:
Lists: pgsql-sql
On Sun, 15 May 2011 07:39:06 +0900,
Ian Lawrence Barwick <barwick(at)gmail(dot)com> wrote:

[...]

> Your query doesn't have an explicit join and is producing a cartesian
> result.

> I don't think a self- join will work here; a subquery should produce
> the result you're after:

> SELECT * FROM tmp t1 WHERE NOT EXISTS(SELECT TRUE FROM tmp t2 WHERE
> t2.b=t1.a);

This produces exactly the result I'm after.  I'll need to understand the
EXISTS statement there in more detail.

Thanks!

-- 
Seb


In response to

pgsql-sql by date

Next:From: Jasen BettsDate: 2011-05-15 02:36:46
Subject: Re: self join
Previous:From: Ian Lawrence BarwickDate: 2011-05-14 22:39:06
Subject: Re: self join

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group