简体   繁体   English

编写内部联接的更好方法?

[英]Better Approach of writing Inner Join?

Which approach should I use ? 我应该使用哪种方法?

This 这个

Select * from table1,table2 where table1.id=table2.id;

or 要么

Select * from table1 inner join table2 on table1.id=table2.id;

Note : Id is foriegn Key . 注意: Id是外键。

在大多数现代RMDBS中,两者都会产生相同的执行计划,但是第二种是推荐的形式,因为它可以在您声明所说的join之后立即弄清楚join条件是什么

If your query gets big as they do, the second style is usually regarded as easier to read and comprehend as the JOIN and the WHERE parts of the query are separated. 如果您的查询变得如此庞大,则通常认为第二种样式更易于阅读和理解,因为查询的JOIN和WHERE部分是分开的。

Select * from table1 
INNER JOIN table2 on table1.id=table2.id
INNER JOIN table3 on table1.id=table3.id
WHERE table2.something = 1

Indeed both styles should have the same execution pan under the hood. 确实,两种样式在引擎盖下应具有相同的执行力。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM