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
精彩评论