From: Harald Fuchs <hari.fuchs@gmail.com>
To: pgsql-sql@postgresql.org
Subject: Re: self join
Date: Sun, 15 May 2011 10:04:30 +0200
Message-ID: <86ei40xucx.fsf@mgm.protecting.net> (raw)
References: <87y629rl34.fsf@kolob.subpolar.dyndns.org>
<iqne7u$ssa$2@reversiblemaps.ath.cx>
In article <iqne7u$ssa$2@reversiblemaps.ath.cx>,
Jasen Betts <jasen@xnet.co.nz> writes:
> On 2011-05-14, Seb <spluque@gmail.com> wrote:
>> Hi,
>>
>> This probably reflects my confusion with how self joins work.
>>
>> Suppose we have this table:
>> If I want to get a table with records where none of the values in column
>> b are found in column a, I thought this should do it:
> use the "NOT IN" operator with a subquery to retch the disallowed
> values.
> select * from tmp where a NOT IN (select b from tmp);
The third way is an OUTER JOIN:
SELECT t1.a, t1.b
FROM tmp t1
LEFT JOIN tmp t2 ON t2.b = t1.a
WHERE t2.b IS NULL;
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 using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: hari.fuchs@gmail.com
Subject: Re: self join
In-Reply-To: <86ei40xucx.fsf@mgm.protecting.net>
* 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