Subject | Re: Subquery executing for every row in parent query? |
---|---|
Author | pavle.grebenar |
Post date | 2011-04-15T06:29:31Z |
Hi !
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
)
> try "exists" instead of "in"maybe this one is better:
>
>
>
> 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
>
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
)