If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > inner join efficiency compaired with where

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-21-03, 19:50
ebow ebow is offline
Registered User
 
Join Date: Oct 2003
Location: melbourne
Posts: 4
inner join efficiency compaired with where

I've been trying to find out if within mysql there is a difference in efficiency between an "inner join" and a join made within the where.

eg.
using an inner join
SELECT * FROM table_a INNER JOIN table_b ON table_a.id = table_b.id

or within the where
SELECT * FROM table_a, table_b WHERE table_a.id = table_b.id

-----------

Does mysql handle these statements differently? and if so than which is better practice? and which is more efficient?

Thanks,
ebow
Reply With Quote
  #2 (permalink)  
Old 10-21-03, 19:54
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
i really don't know whether there is a difference in efficiency, but i would be hugely surprised if there is

but as for better practice, the JOIN syntax is far better

rudy
Reply With Quote
  #3 (permalink)  
Old 10-21-03, 20:06
ebow ebow is offline
Registered User
 
Join Date: Oct 2003
Location: melbourne
Posts: 4
cool, thanks for that. Till now I've only been using statements within the WHERE clause to join the tables (or LEFT JOIN where needed) but then spotted someone elses code using the INNER JOIN and was interested to know if there's a better way.

Do you know if mysql actually deals with the queries differently?

as in, it was suggested to me that when using an inner join mysql links all the tables together and then you refine that through your WHERE statements and that when joining withing the WHERE statement (eg. table_a.id = table_b.id) it loops through to do the joins? ... hmmm, I don't know if that makes sense ... but i don't know how to explain it any better sorry?
Reply With Quote
  #4 (permalink)  
Old 10-21-03, 20:25
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
i dunno, man

like i said, i don't really know the internals

however, as i also mentioned in the article Subquery or join? (registration required, but it's free), it is more important to make sure you are getting the correct results than to worry about the internal efficiency of a piece of software that countless hundreds of man-years went into...


rudy
Reply With Quote
  #5 (permalink)  
Old 10-21-03, 21:06
ebow ebow is offline
Registered User
 
Join Date: Oct 2003
Location: melbourne
Posts: 4
good call.

Thanks for that. I'll have a read of your article.

have a groovy day
Reply With Quote
  #6 (permalink)  
Old 10-21-03, 21:32
sundialsvcs sundialsvcs is offline
Registered User
 
Join Date: Oct 2003
Posts: 706
Exclamation

I don't know which might be "more efficient" .. that's up to the query execution planner .. but I do know which one is more descriptive, and that is "a join." So that's the syntax I think you should use.
__________________
ChimneySweep(R): fast, automatic
table repair at a click of the
mouse! http://www.sundialservices.com
Reply With Quote
  #7 (permalink)  
Old 10-21-03, 22:27
ebow ebow is offline
Registered User
 
Join Date: Oct 2003
Location: melbourne
Posts: 4
that's a good way of putting it "descriptive".

yeah, you guys have convinced me to use these a lot more regularly.

Thanks
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On