SQL 内连接与等连接相同吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5471063/
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
Is inner join the same as equi-join?
提问by user578816
Can you tell me if inner join and equi-join are the same or not ?
你能告诉我内连接和等连接是否相同吗?
回答by
An 'inner join' is not the same as an 'equi-join' in general terms.
一般而言,“内部联接”与“等联接”不同。
'equi-join'means joining tables using the equality operator or equivalent. I would still call an outer join an 'equi-join' if it only uses equality (others may disagree).
'equi-join'表示使用相等运算符或等效运算符连接表。如果外连接只使用相等(其他人可能不同意),我仍然会称它为“等连接”。
'inner join'is opposed to 'outer join'and determines how to join two sets when there is no matching value.
回答by Osy
The answer is NO.
答案是不。
An equi-joinis used to match two columns from two tables using explicit operator =:
等连接用于使用显式运算符=匹配两个表中的两列:
Example:
例子:
select *
from table T1, table2 T2
where T1.column_name1 = T2.column_name2
An inner joinis used to get the cross product between two tables, combining all records from both tables. To get the right result you can use a equi-join or one natural join (column names between tables must be the same)
内连接用于获取两个表之间的叉积,合并两个表中的所有记录。要获得正确的结果,您可以使用等值联接或自然联接(表之间的列名必须相同)
Using equi-join (explicit and implicit)
使用 equi-join(显式和隐式)
select *
from table T1 INNER JOIN table2 T2
on T1.column_name = T2.column_name
select *
from table T1, table2 T2
where T1.column_name = T2.column_name
Or Using natural join
或使用自然连接
select *
from table T1 NATURAL JOIN table2 T2
HTH
HTH
回答by Luca Tampellini
Simply put: an equi-join is a possible type of inner-joins
简单地说:等连接是一种可能的内部连接
For a more in-depth explanation:
更深入的解释:
An inner-join is a join that returns only rows from joined tables where a certain condition is met. This condition may be of equality, which means we would have an equi-join; if the condition is not that of equality - which may be a non-equality, greater than, lesser than, between, etc. - we have a nonequi-join, called more precisely theta-join.
If we do not want such conditions to be necessarily met, we can have outer joins (all rows from all tables returned), left join (all rows from left table returned, only matching for right table), right join (all rows from right table returned, only matching for left table).
内连接是仅从满足特定条件的连接表中返回行的连接。这个条件可能是相等的,这意味着我们会有一个equi-join;如果条件不是相等的条件 - 可能是不相等,大于,小于,之间等 - 我们有一个nonequi-join,更准确地称为 theta-join 。
如果我们不想满足这样的条件,我们可以有外连接(返回所有表的所有行)、左连接(返回左表的所有行,只匹配右表)、右连接(从右表开始的所有行)表返回,仅匹配左表)。
回答by Shumi Gupta
The answer is No,here is the short and simple for readers.
答案是否定的,这里是简短而简单的读者。
Inner joincan have equality (=) and other operators (like <,>,<>) in the join condition.
内连接可以在连接条件中使用等号 (=) 和其他运算符(如 <、>、<>)。
Equi joinonly have equality (=) operator in the join condition.
等值联接在联接条件中仅具有相等 (=) 运算符。
Equi joincan be an Inner join,Left Outer join, Right Outer join
Equi join可以是内连接、左外连接、右外连接
回答by Abhishek Bhandari
If there has to made out a difference then ,I think here it is .I tested it with DB2. In 'equi join'.you have to select the comparing column of the table being joined , in inner join it is not compulsory you do that . Example :-
如果必须做出区别,那么我认为是这样。我用 DB2 对其进行了测试。在 'equi join' 中,您必须选择要连接的表的比较列,在内部连接中,您不必这样做。例子 :-
Select k.id,k.name FROM customer k
inner join dealer on(
k.id =dealer.id
)
here the resulted rows are only two columns rows
这里结果行只有两列行
id name
But I think in equi join you have to select the columns of other table too
但我认为在 equi join 中你也必须选择其他表的列
Select k.id,k.name,d.id FROM customer k,dealer d
where
k.id =d.id
and this will result in rows with three columns , there is no way you cannot have the unwanted compared column of dealer here(even if you don't want it) , the rows will look like
这将导致行具有三列,您不可能在这里拥有不需要的经销商比较列(即使您不想要它),行看起来像
id(from customer) name(from Customer) id(from dealer)
May be this is not true for your question.But it might be one of the major difference.
对于您的问题,这可能不是真的。但这可能是主要区别之一。
回答by Heli Shah
The answer is YES, But as a resultset. So here is an example.
答案是肯定的,但作为结果集。所以这是一个例子。
Consider three tables:
考虑三个表:
orders(ord_no, purch_amt, ord_date, customer_id, salesman_id)
订单(ord_no、purch_amt、ord_date、customer_id、salesman_id)
customer(customer_id,cust_name, city, grade, salesman_id)
客户(customer_id,cust_name,城市,等级,salesman_id)
salesman(salesman_id, name, city, commission)
销售员(salesman_id,姓名,城市,佣金)
Now if I have a query like this:
现在,如果我有这样的查询:
Find the details of an order.
查找订单的详细信息。
Using INNER JOIN:
使用内连接:
SELECT * FROM orders a INNER JOIN customer b ON a.customer_id=b.customer_id
INNER JOIN salesman c ON a.salesman_id=c.salesman_id;
Using EQUI JOIN:
使用EQUI JOIN:
SELECT * FROM orders a, customer b,salesman c where
a.customer_id=b.customer_id and a.salesman_id=c.salesman_id;
Execute both queries. You will get the same output.
执行这两个查询。您将获得相同的输出。
Coming to your question There is no difference in output of equijoin and inner join. But there might be a difference in inner executions of both the types.
来到你的问题equijoin 和内连接的输出没有区别。但是这两种类型的内部执行可能存在差异。