oracle JOINS 和 SUBQUERIES 之间有什么区别?我们可以用连接做的任何事情也可以用子查询完成,反之亦然?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7705591/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 00:21:28  来源:igfitidea点击:

What is difference between JOINS and SUBQUERIES?Can anything we can do with joins can be done with subqueries also or vice-versa?

sqldatabaseoracle

提问by Gautam Bhalla

Possible Duplicate:
SQL: Join vs. subquery

可能的重复:
SQL:加入与子查询

Is there anything that we can do with joins but not with subqueries or vice-versa?

有什么我们可以对连接做但不能对子查询做的事情,反之亦然?

回答by SBerg413

In most cases with enterprise applications, it's not just a question of IF something can be done, but HOW it is done. Generally speaking, Joins are faster and less expensive than subqueries. Ton of other posts on this subject on SO. Here's one: Join vs. sub-query

在大多数企业应用程序的情况下,这不仅仅是是否可以完成某事的问题,而是如何完成的问题。一般来说,连接比子查询更快,成本更低。关于这个主题的大量其他帖子。这是一个: 加入与子查询

回答by Icarus

Frankly, I can't think of a case where one thing can't be achieved from either method (subquery or join).

坦率地说,我想不出任何一种方法(子查询或连接)都无法实现一件事的情况。

To me it's more about readability and performance. For example, a subquery might be slower whereas a join might take advantage of certain indexes. At least from the DBMS standpoint, I would imagine, should be easier to optimize a join when analyzing the expression.

对我来说,更多的是关于可读性和性能。例如,子查询可能较慢,而连接可能会利用某些索引。至少从 DBMS 的角度来看,我认为在分析表达式时优化连接应该更容易。

Consider the case of several joins expressed as subqueries, for example. To most people, seeing the statement expressed as a Left, Rightor Innerjoin would make it easier to understand and maintain. I even avoid using implicit joins since they hide the intent. In other words, I prefer to express a join as from table a inner join table b on a.id=b.idvs from table a, table b where a.id=b.id.Implementing joins as subqueries make it even less readable, IMO.

例如,考虑多个连接表示为子查询的情况。对大多数人来说,看到表达为Left,RightInnerjoin的语句会更容易理解和维护。我什至避免使用隐式连接,因为它们隐藏了意图。换句话说,我更喜欢将连接表示为from table a inner join table b on a.id=b.idvsfrom table a, table b where a.id=b.id.实现连接,因为子查询使其可读性更低,IMO。