Re: the best way to get some records not in another table

Поиск
Список
Период
Сортировка
От Christoph Haller
Тема Re: the best way to get some records not in another table
Дата
Msg-id 3E772384.A397FE7D@rodos.fzk.de
обсуждение исходный текст
Ответ на the best way to get some records not in another table  ("jack" <datactrl@tpg.com.au>)
Список pgsql-sql
>
> Try to get some records not in another table. As the following, please

> advise which one will be the best way to do. Or is there any other way
to do
> better?
>
> SELECT DISTINCT a.c1
> FROM test_j2 a
> WHERE a.c1 NOT IN (SELECT DISTINCT b.c1 FROM test_j1 b);
>
> SELECT a.c1 FROM test_j2 a
> EXCEPT
> SELECT b.c1 FROM test_j1 b;
>
IN resp. NOT IN clauses are known to be slow.

SELECT DISTINCT a.c1
FROM test_j2 a
WHERE NOT EXISTS
(SELECT b.c1 FROM test_j1 b WHERE b.c1 = a.c1) ;

Can't tell if EXISTS performs better than EXCEPT,
have a look at the EXPLAIN output.

Regards, Christoph




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

Предыдущее
От: jasiek@klaster.net
Дата:
Сообщение: Re: Count equals 0
Следующее
От: "Miguel Carvalho"
Дата:
Сообщение: Trigger issue, bug? on 7.2.1