Subject Re: [ib-support] alternatives to "where X not in..."
Author Lucas Franzen
Jordi,


Jordi Galvez schrieb:
>
> Hi list,
>
> I found that an SQL statement like:
>
> select somefields
> from sometable
> where thisfield not in (select thistfield from thistable)
>
> is really slow when the tables have a high number of records. So is there any better alternative to this? (joins work well when the statement is "where X in", but how to do the same in a "not in" case?)
>
> Thanks in advance.

You can use EXISTS and NOT EXISTS for sth. like this.

SELECT somefields
FROM sometable
WHERE NOT EXISTS ( select thisfield FROM thistable where ... )

Luc.