自然连接与内部连接之间的区别 [英] Difference between natural join and inner join

查看:270
本文介绍了自然连接与内部连接之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自然联接和内部联接有什么区别?

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.部分将不在列名称中;您只需要column1column2column1column3作为标题.)

(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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆