我有一个关于oracle Query的新手问题。我想查询2个表中不相等的所有项目。
我的桌子就像这样
A,
NAME VAL1 VAL2
HEAD1 400 80
HEAD2 300 70
HEAD3 299 49
HEAD4 199 59
和表B,
NAME VAL1 VAL2
HEAD1 400 80
HEAD2 300 70
HEAD3 200 60
HEAD4 100 50
和我的查询,
SELECT A.NAME, A.VAL1 VALUEA1, B.VAL1 VALUEB1 FROM A, B
WHERE (SELECT B.VAL1 FROM B WHERE A.VAL1 != B.VAL1)
我的预期输出将是这样的
NAME VALUEA1 VALUEB1
HEAD3 299 200
HEAD4 199 100
请帮我解决问题
答案 0 :(得分:3)
我认为标准JOIN
应该有效:
select a.name, a.val1, b.val1 as bval1
from a
join b on a.name = b.name
where a.val1 <> b.val1
答案 1 :(得分:2)
试试这个:
Select A.Name, A.VAL1 AS VALUEA1, A.VAL2 AS VALUEB1
From TableA as A, TableB As B
Where A.NAME = B.NAME AND A.VAL2 != B.VAL2