欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

oracle natural using join 区别

程序员文章站 2022-06-16 19:21:21
...

一.Oracle Natural join create table test_table_A(id number primary key,name varchar(32));create table test_table_B(id number primary key,name varchar(32),des varchar(32));select *from test_table_A;select *from test_table_B;insert into test

一.Oracle Natural join

create table test_table_A(id number primary key,name varchar(32));
create table test_table_B(id number primary key,name varchar(32),des varchar(32));
select *from test_table_A;
select *from test_table_B;
insert into test_table_A(id, name) values(1,'cuiyaonan20 a');
insert into test_table_A(id, name) values(2,'cuiyaonan200 a');
insert into test_table_A(id, name) values(3,'cuiyaonan2000 a');
insert into test_table_A(id, name) values(4,'cuiyaonan2000@163.com a ');

insert into test_table_B values(1,'cuiyaonan20 a','des 1');
insert into test_table_B values(2,'cuiyaonan200 a','des 2');
insert into test_table_B values(3,'cuiyaonan2000 a','des 3');
insert into test_table_B values(4,'cuiyaonan20 b','des 1');
insert into test_table_B values(5,'cuiyaonan200 b','des 2');
insert into test_table_B values(6,'cuiyaonan2000 b','des 3');

在pl/sql中运行如上实例代码

然后执行:

select *from test_table_a natural join test_table_b;
显示结果为:

oracle natural using join 区别

这就是自连接,A表与B表 如果有同名字段,且字段类型一致,就会整合判断内容是否相等相等就做笛卡尔积.


一.Oracle using join

执行如下代码:

select *from test_table_a join test_table_b using(name);

显示结果为:

oracle natural using join 区别

非常明显,using就是相对于natural而言制定了 一列进行匹配(前提条件一致,字段同名,类型一致)