sql - Would it be better to rewrite this query using EXISTS instead of IN? How would I do that? -
i have following, , i've read it's improve avoid "in" , utilize "exists" instead (1, 2). though i've read exists faster , more consistent, don't think i've grasped exclusively why is, or how go rewriting utilize exists instead.
select qryaccountnamesconcat.accountid, qryaccountnamesconcat.accountname, qryaccountnamesconcat.jobtitle qryaccountnamesconcat (((qryaccountnamesconcat.accountid) in ( select accountid tblaccount accounttypeid in (1, 2)) or qryaccountnamesconcat.accountid in ( select childaccountid qryaccjunctiondetails parentaccounttypeid in (1, 2)) ));
basically, accounttypeid = 1 or 2 trade or private client account, looking accounts are, or children of (usually employees of) client accounts.
i not know if exists
improve in
ms access (although exists
performs improve in
in other databases). however, write as:
select anc.accountid, anc.accountname, anc.jobtitle qryaccountnamesconcat anc exists (select 1 tblaccount a.accounttypeid in (1, 2) , anc.accountid = a.accountid ) or exists (select 1 qryaccjunctiondetails jd jd.parentaccounttypeid in (1, 2) , jd.childaccountid = anc.accountid );
for best performance, want index on tblaccount(accountid, accounttypeid)
, qryaccjunctiondetails(childaccountid, parentaccounttypeid)
.
sql ms-access
No comments:
Post a Comment