Oracle (+) outer join and constant values

后端 未结 4 2265
情书的邮戳
情书的邮戳 2021-02-09 13:08

I\'m running into an issue with which I can\'t figure out how to correctly configure a join. I\'m using reporting software that utilizes the (+) indicators in the WHERE clause f

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-09 13:44

    Join option 1 is the equivalent of:

    SELECT *
    FROM   TXN
           LEFT OUTER JOIN CHK
           ON ( TXN.CHK_ID = CHK.CHK_ID )
    WHERE  TXN.CURRENT = 'Y'
    AND    CHK.CURRENT = 'Y'
    

    However, since any rows that are in the result set will have CHK.CURRENT = 'Y' (a non-null value) then those rows must have matched on CHK_ID and the query is actually the equivalent of:

    SELECT *
    FROM   TXN
           INNER JOIN CHK
           ON ( TXN.CHK_ID = CHK.CHK_ID )
    WHERE  TXN.CURRENT = 'Y'
    AND    CHK.CURRENT = 'Y'
    

    Join option 2 is the equivalent of:

    SELECT *
    FROM   TXN
           LEFT OUTER JOIN CHK
           ON (    TXN.CHK_ID  = CHK.CHK_ID
               AND CHK.CURRENT = 'Y' )
    WHERE  TXN.CURRENT = 'Y'
    

    You can make Join option 1 the equivalent of option 2 using:

    SELECT *
    FROM   TXN
           LEFT OUTER JOIN CHK
           ON ( TXN.CHK_ID = CHK.CHK_ID )
    WHERE  TXN.CURRENT = 'Y'
    AND    ( CHK.CURRENT = 'Y' OR CHK.CHK_ID IS NULL )
    

提交回复
热议问题