Re: self join

Поиск
Список
Период
Сортировка
От Harald Fuchs
Тема Re: self join
Дата
Msg-id 86ei40xucx.fsf@mgm.protecting.net
обсуждение исходный текст
Ответ на self join  (Seb <spluque@gmail.com>)
Список pgsql-sql
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;



В списке pgsql-sql по дате отправления:

Предыдущее
От: Jasen Betts
Дата:
Сообщение: Re: self join
Следующее
От: Jasmin Dizdarevic
Дата:
Сообщение: Performance of NOT IN and <> with PG 9.0.4