开发者

Two mysql queries, same results: is one better then the other?

开发者 https://www.devze.com 2023-01-31 15:00 出处:网络
These two mysql queries return the same result set. Either gives me the results I want. But is one preferable over the other?

These two mysql queries return the same result set. Either gives me the results I want. But is one preferable over the other?

SELECT links.*, users.user_name 
FROM links 
LEFT开发者_Python百科 JOIN terms 
ON links.link_id = terms.terms_link_id 
LEFT JOIN users 
ON links.link_user = users.user_id 
WHERE terms.terms_tag_id = ?

-

SELECT links.*, users.user_name 
FROM links, users, terms 
WHERE links.link_id = terms.terms_link_id 
AND links.link_user = users.user_id 
AND terms.terms_tag_id = ?


Looks like this answers your question: Inner join vs Where


Both are bad

SELECT links.*, users.user_name
FROM links 
INNER JOIN terms 
  ON links.link_id = terms.terms_link_id AND terms.terms_tag_id = $tag_id
INNER JOIN users 
  ON links.link_user = users.user_id;

Only one rule

  • do an execution plan, DESC EXTENDED YOUR_QUERY; to check how optimization can be done on mysql
0

精彩评论

暂无评论...
验证码 换一张
取 消