“,”“natural join”“natural left outer join”“natural right outer join”的用法总结
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了“,”“natural join”“natural left outer join”“natural right outer join”的用法总结相关的知识,希望对你有一定的参考价值。
“,”:代表笛卡尔积;
“natural join”:代表自然连接,即同名列等值连接;
“natural left outer join”:表示左外连接;
“natural right outer join”:表示右外连接。
注意:以下的写法在Oracle中都是不正确的。
1.r1 join r2
2.r1 inner join r2
3.r1 left outer join r2(如果要用左外连接,需要加natural关键字,否则,语法错误)
4.r1 right outer join r2
同时,需要注意:natural join 和 natural inner join是一样的。因为自然连接默认就是内连。
接下来,看代码示例:
1.建表,插入数据:
drop table relation2; drop table relation1; create table relation1( id number(10) not null, r1_col1 varchar2(50), r1_col2 varchar2(50), primary key (id) ); create table relation2( id number(10) not null, r2_col1 varchar2(50), r2_col2 varchar2(50), primary key (id) ); insert into relation1 values(1,‘A1‘,‘A2‘); insert into relation1 values(2,‘B1‘,‘B2‘); insert into relation1 values(3,‘C1‘,‘C2‘); insert into relation1 values(4,‘D1‘,‘D2‘); insert into relation1 values(5,‘N1‘,‘N2‘); insert into relation1 values(6,‘M1‘,‘M2‘); ----------------------------------------------- insert into relation2 values(1,‘E1‘,‘E2‘); insert into relation2 values(2,‘F1‘,‘F2‘); insert into relation2 values(3,‘G1‘,‘G2‘); insert into relation2 values(4,‘H1‘,‘H2‘); insert into relation2 values(7,‘X1‘,‘X2‘); insert into relation2 values(8,‘Y1‘,‘Y2‘);
插入的结果:
relation1:
relation2:
2.查询
select * from relation1,relation2;--笛卡尔积
总共36条记录。行号为37是因为第一条记录从第二行开始。
select * from relation1 natural join relation2;--自然连接(默认内连)
select * from relation1 natural inner join relation2;--自然连接(显式内连)
select * from relation1 natural left outer join relation2;--自然左外连接
select * from relation1 natural right outer join relation2;--自然右外连接
以上是关于“,”“natural join”“natural left outer join”“natural right outer join”的用法总结的主要内容,如果未能解决你的问题,请参考以下文章
(', CROSS, FULL, INNER, JOIN, LEFT, NATURAL, ON, RIGHT 或 USING 预期,得到'WITH'
MySQL的几种连接 join/inner join/cross join/逗号/left join/right join/natural join
[Javascript Natural] Break up language strings into parts using Natural