LEFT-JOIN 代替 oracle (+) with where 子句

LEFT-JOIN instead of oracle (+) with where clause

上次 post 由于“重复”post(10 年前)而被删除,但我无法根据我的查询调整答案。

我想用 LEFT JOIN 替换 oracle (+),但我想不通。

FROM a,b,c
WHERE b.a  = '101'
AND a.a    = '202'
AND b.c    = a.c
AND a.d    = c.d(+)
AND ROWNUM = 1;

我试过的是

FROM a
LEFT JOIN c
ON a.d = c.d
WHERE b.a  = '101'
AND a.a    = '202'
AND b.c    = a.c
AND ROWNUM = 1;

但由于我从未从 table b 获取数据,所以它失败了。

您想 INNER JOINb 然后 LEFT OUTER JOINc:

FROM  a
      INNER JOIN b
      ON (b.c = a.c)
      LEFT OUTER JOIN c
      ON (a.d = c.d)
WHERE b.a  = '101'
AND   a.a    = '202'
AND   ROWNUM = 1;

您的查询:

FROM a,b,c
WHERE b.a  = '101'
AND a.a    = '202'
AND b.c    = a.c
AND a.d    = c.d(+)
AND ROWNUM = 1;

FROM 子句中的逗号表示 CROSS JOIN.

但是,在 WHERE 子句中您有:

  • b.c = a.c 将表 ab 之间的连接条件从 CROSS JOIN 更改为 INNER JOIN;和
  • a.d = c.d(+) 将表 ac 之间的连接条件从 CROSS JOIN 更改为 LEFT OUTER JOIN.