| From: | Adam Ruth <aruth(at)intercation(dot)com> |
|---|---|
| To: | Graham Leggett <minfrin(at)sharp(dot)fm> |
| Cc: | pgsql-general(at)postgresql(dot)org |
| Subject: | Re: Postgresql sql query - selecting rows outside a join |
| Date: | 2003-12-01 17:48:24 |
| Message-ID: | 8F83FCCA-2426-11D8-B2A5-000A959D1424@intercation.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
On Dec 1, 2003, at 10:15 AM, Graham Leggett wrote:
> Hi all,
>
> I am trying to do a query that returns all rows that are _not_ part of
> a join, and so far I cannot seem to find a query that doesn't take 30
> minutes or more to run.
>
> The basic query is "select * from tableA where tableA_id NOT IN (select
> tableA_id from tableB)".
>
> Is there a more efficient way of doing this?
>
> Regards,
> Graham
> --
>
This should be more efficient:
select * from tableA where not exists (select null from tableB where
tableA_id = tableA.tableA_id);
Version 7.4 fixes the slow IN - NOT IN, but I haven't tested it myself
yet to see how it compares to this.
Adam Ruth
| From | Date | Subject | |
|---|---|---|---|
| Next Message | B. van Ouwerkerk | 2003-12-01 17:50:38 | Re: PostgreSQL from a newcomers perspective |
| Previous Message | Rick Gigger | 2003-12-01 17:41:20 | Re: Humor me: Postgresql vs. MySql (esp. licensing) |