问题描述
自然联接和内部联接有什么区别?
What is the difference between a natural join and an inner join?
推荐答案
INNER JOIN和NATURAL JOIN之间的一个重要区别是返回的列数.
One significant difference between INNER JOIN and NATURAL JOIN is the number of columns returned.
考虑:
TableA TableB
+------------+----------+ +--------------------+
|Column1 | Column2 | |Column1 | Column3 |
+-----------------------+ +--------------------+
| 1 | 2 | | 1 | 3 |
+------------+----------+ +---------+----------+
Column1上的TableA和TableB的INNER JOIN
将返回
The INNER JOIN
of TableA and TableB on Column1 will return
SELECT * FROM TableA AS a INNER JOIN TableB AS b USING (Column1);
SELECT * FROM TableA AS a INNER JOIN TableB AS b ON a.Column1 = b.Column1;
+------------+-----------+---------------------+
| a.Column1 | a.Column2 | b.Column1| b.Column3|
+------------------------+---------------------+
| 1 | 2 | 1 | 3 |
+------------+-----------+----------+----------+
ColumnA上TableA和TableB的NATURAL JOIN
将返回:
The NATURAL JOIN
of TableA and TableB on Column1 will return:
SELECT * FROM TableA NATURAL JOIN TableB
+------------+----------+----------+
|Column1 | Column2 | Column3 |
+-----------------------+----------+
| 1 | 2 | 3 |
+------------+----------+----------+
避免重复的列.
(根据标准语法的AFAICT,您不能在自然连接中指定连接列;该连接严格基于名称.另请参见维基百科.)
(AFAICT from the standard grammar, you can't specify the joining columns in a natural join; the join is strictly name-based. See also Wikipedia.)
(内部连接输出中有一个作弊项; a.
和b.
部分将不在列名称中;您只需要column1
,column2
,column1
, column3
作为标题.)
(There's a cheat in the inner join output; the a.
and b.
parts would not be in the column names; you'd just have column1
, column2
, column1
, column3
as the headings.)
这篇关于自然连接与内部连接之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!