Subject Re: [firebird-support] is there a way around the IN clause?
Author Lucas Franzen
Gary,


> The following query takes 44 seconds to return.
>
> select
> c.name, c.surname, c.telephone, c.lastorderdate
> from customers c
> where c.link not in (select customerlink from orders where recdate >
> '01-jan-2004' and recdate < '01-feb-2004' and branchcode = 'SAN')
> and c.branchcode = 'SAN'
> order by
> c.lastorderdate desc,1,2

select
c.name, c.surname, c.telephone, c.lastorderdate
from customers c
where NOT EXISTS (
select customerlink from orders
where
recdate > '01-jan-2004' and
recdate < '01-feb-2004' and
branchcode = 'SAN'
)
and c.branchcode = 'SAN'
order by
c.lastorderdate desc,1,2

I dare to say that this one is much faster ;-)


Luc.