zoukankan      html  css  js  c++  java
  • Oracle外连接与条件的组合

    由于很少使用SQL 92语法,今天写个outer join的时候被搞晕了。参考了一些例子后整理如下。总结,“inter join on”中的条件是对table进行joining的record 进行filter, 而where 对结果集进行filter。

    Table A:

    Key    Value
    1        A1

    2        A2

    3        A3

    Table B:

    Key    Value

    1        B1

    2        B2

    4        B4

    --============================

    select A.*, B.* from A outer join B

    on A.key = b.key;

    Key   Value   Key   Value

    1        A1        1       B1

    2        A2        2       B2

    3        A3  

    /* 普通的A outer join B */

    --============================

    select A.*, B.* from A outer join B

    on A.key = b.key

     and A.key = '1';

    Key   Value   Key   Value

    1        A1        1       B1

    2        A2

    3        A3  

    /* A 只有记录 key='1' 参与了outer join,其他记录保留在结果中 */

    --============================

    select A.*, B.* from A outer join B

    on A.key = b.key

     and A.key = '1'

    where A.key <> '3' ;

    Key   Value   Key   Value

    1        A1        1       B1

    2        A2

    /* A 只有记录 key='1' 参与了outer join,结果中有条件 key <> '3' */

  • 相关阅读:
    学习mongodb简单安装、连接数据库、增删改查
    第三方模块glup学习
    npm 借助第三方模块nrm切换淘宝源
    nodemon 学习
    bootstrap和ie浏览器兼容性问题怎么解决?
    所得税
    债务重组
    非货币性资产交换
    政府补助
    收入 费用 和利润
  • 原文地址:https://www.cnblogs.com/pekkle/p/6568826.html
Copyright © 2011-2022 走看看