Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Subselects better than multiple wheres?

Status
Not open for further replies.

jennyflower

Programmer
Oct 10, 2006
60
GB
Hi, I have a query like this:

select tb1.fd1, tb1.fd2, tb1.fd3, tb2.fd1, tb2.fd2, tb2.fd3 from tb1 join tb2 on tb1.fd1=tb2.fd1 where tb1.fd1 = 1 and (tb1.fd2 = 'P' or tb1.fd2 = 'Q' or tb1.fd2 = 'R') and tb1.fd3 > CURRENT_DATE and tb2.fd1 = 3 and tb2.fd2 <= CURRENT_DATE and tb2.fd3 != NULL order by tb1.fd1

would this type of query be better optimised and probably run faster if i were to split it into 2 subselects like

select tb1.fd1, qrytb1.fd2, qrytb1.fd3, qrytb2.fd1, qrytb2.fd2, qrytb2.fd3
from tb1
join (select * from tb1) as qrytb1 on tb1.fd1=qrytb1.fd1
join (select * from tb2) as qrytb2 on tb1.fd1=qrytb2.fd1
order by tb1.fd1

Hope this makes sese to someone!!

Jen
 
i can't tell for sure, because these two queries look to me different, but you can use

EXPLAIN ANALYZE and the server will tell you, what is doing and how long does it takes
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top