Subject Re: Subquery executing for every row in parent query?
Author pavle.grebenar
Hi !

> try "exists" instead of "in"
>
>
>
> select distinct DOCSUSERCANVIEWEXTERNAL.DOCUMENTID
> from DOCSUSERCANVIEWEXTERNAL
> where
> EXISTS
> (
> select distinct PERSONNELHISTORY.GROUPID
> from PERSONNELHISTORY
> where PERSONNELHISTORY.HISTORYCODE in (2,3)
> and PERSONNELHISTORY.DATETIMECREATE >= '1-Mar-1901'
> and not PERSONNELHISTORY.GROUPID=0
> AND PERSONNELHISTORY.GROUPID=DOCSUSERCANVIEWEXTERNAL.GROUPID
> )
>
> Karol Bieniaszewski
>

maybe this one is better:

select distinct DOCSUSERCANVIEWEXTERNAL.DOCUMENTID
from DOCSUSERCANVIEWEXTERNAL
where not (DOCSUSERCANVIEWEXTERNAL.GROUPID = 0)
and EXISTS (
select 1 from PERSONNELHISTORY
where PERSONNELHISTORY.HISTORYCODE in (2,3)
and PERSONNELHISTORY.DATETIMECREATE >= '1-Mar-1901'
AND PERSONNELHISTORY.GROUPID=DOCSUSERCANVIEWEXTERNAL.GROUPID
)