zoukankan      html  css  js  c++  java
  • 谈谈oracle里的join、left join、right join


    create table l as
    select 'left_1' as str,'1' as v from dual union all
    select 'left_2' ,'2' as v from dual union all
    select 'left_3' ,'3' as v from dual union all
    select 'left_4' ,'4' as v from dual ;

    create table r as
    select 'right_3' as str,'3' as v, 1  as status from dual union all
    select 'right_4' as str,'4' as v, 0  as status from dual union all
    select 'right_5' as str,'5' as v, 0  as status from dual union all
    select 'right_6' as str,'6' as v, 0  as status from dual ;

    select * from l; --where l.v not in (select r.v from r )

    select * from r

    --1. inner join 返回两表相匹配的数据  即 交集
    select l.str as left_str,r.str as right_str from l
    inner join r on l.v=r.v
    order by 1,2;

    select l.str as left_str,r.str rigth_str from l,r
    where l.v=r.v
    order by 1,2;

    --2.left join  左表为主表,左表返回全部数据,右表只返回与左表相匹配的数据
    select l.str as left_str,r.str right_str from l
    left join r on l.v=r.v
    order by 1,2;

    select l.str as left_str,r.str as right_str from l,r
    where l.v=r.v(+)
    order by 1,2;

    select l.str as left_str,r.str as right_str from l,r
    where l.v=r.v
    order by 1,2;
     
    --3.right join 右表为主表,左表只返回与右表相匹配的数据
    select l.str as left_str,r.str as right_str from l
    right join r on l.v=r.v
    order by 1,2;

    select l.str as left_str,r.str right_str from l,r
    where l.v(+)=r.v
    order by 1,2;

    --4. 左右表均返回全部的数据,但是只有相匹配的数据显示在一行,非匹配的数据只显示一个表的数据
    select l.str as left_str,r.str as right_str from l
    full join r on r.v=l.v
    order by 1,2;


  • 相关阅读:
    JAVA BigDecimal 小数点处理
    对 Element UI table中数据进行二次处理
    Kettle-User Defined Java Class使用-大写转换
    多线程-同步函数
    多线程-银行分批存款
    多线程-并发卖票
    多线程-控制两个线程交替打印
    ztree-可拖拽可编辑的树
    ztree-编辑节点(树节点添加,删除,修改)
    ztree-拖拽(排序树)
  • 原文地址:https://www.cnblogs.com/iyoume2008/p/6395648.html
Copyright © 2011-2022 走看看