在尝试从2个表中进行选择时,我在Oracle中遇到这种情况:
表1
-------------
Col1 Col2
-------------
1 abc
2 aa
3 lab
4 mm
5 nn
6 kk
7 pp
表2
-----------
Col1 Col2
----------
4 xxx
7 yyy
(null) zzz
我想在我的选择中包括Table2的所有行,包括(null)zzz . 我在做的是 -
SELECT column1, column2,….FROM Table1, Table2 Where table1.col1 = Table2.col1(+)
但它没有给我表2中的NULL值行 .
我尝试在col1上使用左外连接的OR条件,但它不起作用 .
SELECT column1, column2,…. FROM Table1, Table2 Where table1.col1 = Table2.col1(+) OR Table2.Col1 IS NULL
这是预期的输出:
Col1 Table1.Col2 Table2.Col2
--------------------------------
1 abc (null)
2 aa (null)
3 lab (null)
4 mm xxx
5 nn (null)
6 kk (null)
7 pp yyy
(null) (null) zzz
1 回答
它似乎你想要的是
FULL OUTER JOIN
SQL Fiddle
Query 1 :
Results :
important 给你的建议是摆脱
(+)
外连接表示法并使用ANSI.. JOIN ON
语法 .