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

时间:2021-08-26 22:14:52

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

这两个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 个解决方案

#1


1  

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
  • 执行计划,DESC扩展了YOUR_QUERY;检查如何在mysql上进行优化

#2


3  

Looks like this answers your question: Inner join vs Where

看起来这回答了你的问题:内连接vs . Where

#1


1  

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
  • 执行计划,DESC扩展了YOUR_QUERY;检查如何在mysql上进行优化

#2


3  

Looks like this answers your question: Inner join vs Where

看起来这回答了你的问题:内连接vs . Where