Oracle JOIN 3 表 - 哪种方式有效或者有什么区别
我可以看到人们以不同的方式进行连接
从a、b、c中选择a.acc、b.acc、c.acc 其中 a.acc=b.acc 且 c.acc = a.acc;
和
选择 a.acc、b.acc、c.acc 加入 a.acc=b.acc JOIN on c.acc = a.acc;
有什么区别吗?我想不会。
I can see people doing joins in different ways
select a.acc, b.acc, c.acc from a, b,c
where a.acc=b.acc and c.acc = a.acc;
and
select a.acc, b.acc, c.acc JOIN on
a.acc=b.acc JOIN on c.acc = a.acc;
Is there any difference? I suppose not.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
就性能而言,没有区别。
考虑到可维护性,我更喜欢第二种方法。使用哪些条件来连接哪些表更加明确,并且更容易看出您是否错过了连接条件。
In terms of performance there is no difference.
I prefer the second approach for maintainability. It is more explicit which conditions are used to join which tables and it is easier to see whether or not you have missed out a join condition.
除了 Mark 指出的使用后一种语法有助于确保您不会无意中错过连接条件之外,SQL 99 语法的一个好处是,如果您的列命名约定是父级和子级中的列名称表匹配时,可以使用 USING 子句而不是 ON 子句,即
这样可以提高代码的可读性,并减少因无意中错误连接表而引入错误的可能性。如果每次我不小心写出一些像
我真正意味着
我会成为一个有钱人的东西时我都会得到五分钱。或者至少有足够的寿司晚餐。
当然,大多数时候,很明显你做错了什么,因为数据完全是错误的,但有时结果足够接近,你并不能立即明显看出你做错了什么,直到很久以后,您发现了错误并追踪了罪魁祸首的查询。如果使用 USING 子句编写查询,基本上不可能犯这种错误
In addition to Mark's point that using the latter syntax helps ensure that you don't inadvertently miss a join condition, one nice thing about the SQL 99 syntax is that if your column naming convention is that the name of the column in the parent and child table matches, you can use the USING clause rather than the ON clause, i.e.
This can improve the readability of the code and decrease the probability that you introduce errors by inadvertently joining tables incorrectly. If I had a nickel for every time I accidentally wrote something like
when I really meant
I'd be a rich man. Or at least have enough for a good sushi dinner.
Most of the time, of course, it's immediately obvious that you've done something wrong because the data is completely screwy but it occasionally happens that the results are sufficiently close that it's not immediately obvious that you've done something wrong and it's not until much later that you discover the bug and track down the culprit query. It's basically impossible to make that sort of mistake if you write the query with the USING clause
如果您的第二个选择是读取
select a.acc, b.acc, c.acc from a JOIN b on a.acc=b.acc JOIN c on c.acc = a.acc;
那么没有什么区别。if your second select is to read
select a.acc, b.acc, c.acc from a JOIN b on a.acc=b.acc JOIN c on c.acc = a.acc;
then there is no difference.