zoukankan      html  css  js  c++  java
  • oracle左连接与外连接

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

    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
  • 相关阅读:
    list tuple dict 方法
    字典的方法
    看不懂的缩写
    canvas画图
    DOM2和DOM3
    表单脚本
    事件
    DOM扩展
    DOM
    BOM
  • 原文地址:https://www.cnblogs.com/wujin/p/2471574.html
Copyright © 2011-2022 走看看