From: | DeJuan Jackson <djackson(at)speedfc(dot)com> |
---|---|
To: | Rory Campbell-Lange <rory(at)campbell-lange(dot)net> |
Cc: | Postgres General <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: using EXISTS instead of IN: how? |
Date: | 2003-07-22 16:40:01 |
Message-ID: | 3F1D68E1.2080903@speedfc.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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)
From | Date | Subject | |
---|---|---|---|
Next Message | Mike Mascari | 2003-07-22 16:46:19 | Re: using EXISTS instead of IN: how? |
Previous Message | Csaba Nagy | 2003-07-22 16:39:30 | Re: using EXISTS instead of IN: how? |