oracle - SQL Query optimization : Taking lots of time -


i having following query used retrieve set of orders:

select count(distinct po.orderid)  postorders po,       processedorders pro  pro.state in ('pending','completed')    , po.comp_code in (3,4)    , pro.orderid = po.orderid 

the query returns result of 4323, , fast enough.

but have put condition such returns if not present in table discarderorders add condition query:

select count(distinct po.orderid)  postorders po,       processedorders pro  pro.state in ('pending','completed')    , po.comp_code in (3,4)    , pro.orderid = po.orderid    , po.orderid not in (select do.order_id discardedorders do) 

the above query takes lot of time , keeps on running. there can query such executes fast? or need execute first query first, , filter based on condition shooting query?

you can try replace:

and po.orderid not in (select do.order_id discardedorders do) 

by

and not exists (select 1 discardedorders do.order_id = po.orderid) 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -