Re: using EXISTS instead of IN: how?

Поиск
Список
Период
Сортировка
От DeJuan Jackson
Тема Re: using EXISTS instead of IN: how?
Дата
Msg-id 3F1D68E1.2080903@speedfc.com
обсуждение исходный текст
Ответ на using EXISTS instead of IN: how?  (Rory Campbell-Lange <rory@campbell-lange.net>)
Список pgsql-general
Rory Campbell-Lange wrote:

>I have been informed that at present (postgres 7.3.2) using IN is not
>advised, and I should  replace it with EXISTS. I can't seem to get it to
>work.
>
>I've tried replacing (example):
>
>    SELECT
>        name
>    FROM
>        people
>    WHERE
>        state IN (
>            SELECT
>                id
>            FROM
>                states
>            WHERE
>                name ~* 'r'
>        );
>
>with
>
>    SELECT
>        name
>    FROM
>        people
>    WHERE
>        exists (
>            SELECT
>                1
>            FROM
>                states
>            WHERE
>                name ~* 'r'
>        );
>
>However the second example simply finds all records in people.
>
>Thanks for any help,
>Rory
>
>
>
try:
 SELECT name FROM people
  WHERE EXISTS(SELECT 1 FROM states
                    WHERE name ~*'r' AND people.state = states.state)


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

Предыдущее
От: Lincoln Yeoh
Дата:
Сообщение: Re: A doubt w.r.t WAL
Следующее
От: Mike Mascari
Дата:
Сообщение: Re: using EXISTS instead of IN: how?