Re: [GENERAL] Negating the list of selected rows of a join

Поиск
Список
Период
Сортировка
От Clark Evans
Тема Re: [GENERAL] Negating the list of selected rows of a join
Дата
Msg-id 36EB7179.206BD7CB@manhattanproject.com
обсуждение исходный текст
Ответ на Negating the list of selected rows of a join  ("Manuel Lemos" <mlemos@acm.org>)
Список pgsql-general
Manuel Lemos wrote:
>
> I want to list the rows of a table with a text field whose values do not
> exist in a similar field of another table.  Basically what I want to get
> is negated results of a join.


Ulf Mehlig wrote:
>    SELECT name FROM table_a
>    WHERE name NOT IN (SELECT name FROM table_b);


Clark Evans wrote:
> SELECT table_a.name, table_a.age
>   FROM table_a
>  WHERE NOT EXISTS (
>           SELECT 'x'
>             FROM table_b
>            WHERE table_b.name = table_a.name
>        );


I'm not sure about how well PostgreSQL handles
these two.  I'd try them both with your data set.
If table_b is small (less than a few thousand rows)
then Ulf's approach would work best.  However,
if table_b is large (more than a thousand)
then I think the other approach may work better
if table_b.name is indexed.

Clark

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

Предыдущее
От: Ulf Mehlig
Дата:
Сообщение: Re: [GENERAL] Negating the list of selected rows of a join
Следующее
От: Ulf Mehlig
Дата:
Сообщение: Re: [GENERAL] Negating the list of selected rows of a join