wujin

最近遇到左连接与外连接的业务,感觉有点模糊,平时用的少,今天小小的总结一些。

oracle连接

内连接(自然连接):只有两个表匹配的才能在结果中出现

外连接

  左连接:显示左边的全部和右边与左边匹配的部分。

  右连接:显示右边的全部与左边与右边匹配的部分

自连接:连接在一张表中

下面通过例子来说明

1.首先实验数据两张表,student,studentclass 中其中classid是关联字段。

这是两张表中的数据,可以看出在student表中赵六的班级在studentclass中没有,在studentclass表中物理班在student表中没有。

左连接

可以看出来,左连接只显示左边的部分,(+)的另一侧位连接的方向,也就是说左边的是否匹配都会显示。

当然左连接也可以用left join来表示,这是在9i里的写法,

select s.id, s.name, st.classname
  from student s
  left join studentclass st on (s.classid = st.classid)

 

右连接

右连接和左连接是相反的。当然右连接也可以用下列sql

select s.id, s.name, st.classname
  from student s
  right join studentclass st on (s.classid = st.classid)

全连接

顺便说一下全连接,全连接用(+)不能表示,只能用full join来表示

 

可以看出全连接是两边的都有。

内连接:

select s.id, s.name, st.classname
  from student s, studentclass st
 where s.classid = st.classid

 

 

分类:

技术点:

相关文章:

  • 2021-09-15
  • 2022-01-15
  • 2022-12-23
  • 2021-12-28
  • 2021-11-16
  • 2022-02-07
  • 2021-12-05
猜你喜欢
  • 2022-01-09
  • 2021-12-09
  • 2022-01-30
  • 2021-07-09
  • 2021-06-19
  • 2022-01-30
  • 2022-02-10
相关资源
相似解决方案