on 2014 Mar 12 10:00 AM
Hi,
The below query retrieves 5000 ids.Need to fine tune in such a way that it takes less time to execute.
select top 5000 ids from table1 t1 join table2 t2 on t1.class=t2.class and t1.pid = t2.pid and isnull(t.bkngpur, '') !='ABC' and (t.rspid = p.spid or (isnull(t.rspid,'') = isnull(p.spid,''))) left join table3 t3 on t.cpid1 = c.cpid left join table4 t4 on t.cpid1 = cp.cpid where status in ('A','B') and Tid != 'PR%' and exDate > (select curdate from table5) and p.rep = 1 and (rrtor in( 'ABC','DEF') or (( Tid in (select tsid from table5 where bid in (select lbid from table6 where pbid in ('abc','def', 'ghi')) or t4.indc = 1)) or (ids in (select tsid from table7 where bid in ( select lbid from table6 where pbid where pbid in ('abc','def', 'ghi') or t4.indc =1) ) )) and t3.col1 in (NULL,'XYZ) and t1.tpid in ('P','Q','R','S') order by 1
Thanks in advance
Request clarification before answering.
Hi,
Thanks for your response.
1.This Query only gives a list of ids.
1 2 3 . . . . 5000
Well this query is taking ~7 seconds to complete.Need to rewrite the query using joins instead of sub queries.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Please answer the questions that Mark and Mikel asked. If you don't answer those questions, there isn't much chance you will get an answer.
"Rewriting the query using joins instead of subqueries" may or MAY NOT help, since the query optimizer often does that automatically... that is like asking for painkillers without answering any medical questions.
User | Count |
---|---|
61 | |
8 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.