Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Subselects better than multiple wheres?

Subselects better than multiple wheres?

Subselects better than multiple wheres?

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!!


RE: Subselects better than multiple wheres?

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close