Oracle数据库,join多表关联方式、union结果集合并

join on :   多表关联

内连接 :与其他表连接

1

2

3

from 表1 t  join 表2 s  on t.字段1 =s.字段2  join 表3 n on n.字段3=t.字段1

from 表1 a ,表2 b,表3c  where a.字段=b.字段

  

自连接: 与自身连接

1

from 表1 t  join 表1 s  on t.字段1 =s.字段1  s.字段1=t.字段1

外连接:左/右连接

1

2

3

left join on     左连接   保证左边表的数据全部显示

right join on    右连接  保证右边表的数据全部显示

  

全连接:保证两边的表的数据全部出现

1

full join on

  

union:结果集合并      

要求:前后数据的列数和字段类型要一致  

例:

1

2

3

4

5

6

7

8

9

10

11

12

select s.name,s.sex,t.cno from student s

union

select t.name,t.sex,t.cno from student t  

去掉重复数据并合并

select s.name,s.sex,t.cno from student s

union  all

select t.name,t.sex,t.cno from student t  

不去掉重复数据并合并

猜你喜欢

转载自blog.csdn.net/w892824196/article/details/84761880