两个mysql查询,结果相同:一个比另一个好吗?

时间:2010-12-20 03:14:51

标签: sql mysql

这两个mysql查询返回相同的结果集。要么给我我想要的结果。但是一个优于另一个吗?

SELECT links.*, users.user_name 
FROM links 
LEFT 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 = ?

2 个答案:

答案 0 :(得分:3)

看起来这回答了你的问题: Inner join vs Where

答案 1 :(得分:1)

两者都糟糕

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;

只有一条规则

  • 执行执行计划,DESC EXTENDED YOUR_QUERY;以检查如何在mysql上进行优化