自然连接和内部连接的区别 [英] Difference between natural join and inner join
问题描述
自然连接和内部连接有什么区别?
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 |
+------------+-----------+----------+----------+
Column1 上 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.)
这篇关于自然连接和内部连接的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!