开发者

Which is better, implicit or explicit join? [duplicate]

This question already has answers here: 开发者_开发问答 Closed 11 years ago.

Possible Duplicate:

SQL JOIN: is there a difference between USING, ON or WHERE?

Which is better:

SELECT `sheet_data`.* 
FROM  `clip`, `sheet_data` 
WHERE `clip`.`mrecord`='8' AND `clip`.`data`=`sheet_data`.`id`

or

SELECT `sheet_data`.* 
FROM  `clip` INNER JOIN `sheet_data` 
  ON  `clip`.`data`=`sheet_data`.`id`
WHERE `clip`.`mrecord`='8'

and why?


In older days, the first was faster, but this is not true anymore. I personally think the INNER JOIN is better, because it is more readable. It shows better the relations between the table. You got those relations in the join, and you do the filtering in the WHERE clause. This separation makes the query more readable. But this is a matter of personal taste.


No. 2 is better for readability, as you can see by looking on the ON clause on which columns you are joining and don't have to scan the whole where clause. But from a performance standpoint, both queries will result in the same execution plan with the same performance.


Generally speaking it's always better to do an explicit join (the second one) because it's more portable. Not all SQL servers implement implicit joins, plus it's easier to tell at a glance what's going on.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜