join on :   多表关联

内连接 :与其他表连接

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.字段

  

自连接: 与自身连接

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

 

外连接:左/右连接

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

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

  

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

full join on

  

union:结果集合并      

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

例:

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   

不去掉重复数据并合并

  

 

相关文章:

  • 2021-12-24
  • 2022-12-23
  • 2021-11-15
  • 2022-01-31
  • 2021-06-15
  • 2022-12-23
  • 2021-10-06
  • 2022-12-23
猜你喜欢
  • 2022-01-27
  • 2021-11-10
  • 2022-01-18
  • 2022-01-25
  • 2022-12-23
  • 2021-09-23
  • 2022-12-23
相关资源
相似解决方案