我想比較兩個不同表之間的值,只返回差異,但我努力想出一個查詢。SQL比較不匹配值
我有一個僱員標籤1和僱員標籤2.我比較dev和測試之間的數據。
employee1
id1 cd1 desc1
1 reg regular
2 temp temporary
3 reg regular
4 new new hire
5 del terminated
和Employee2
id2 cd2 desc2
1 reg regular
2 temp temporary-456
3 reg regular-123
4 new new hire
5 del terminated
我的結果集應該是(我將在EMPLID聯接,CD)
id cd1 desc1 cd2 desc2
1 reg regular reg regular-123
2 temp temporary temp temporary-456
我試過這種方法
SELECT Distinct EMPL_ID, cd1, desc1, CD2, desc2
FROM empl 1, empl2
WHERE EMPL_ID1= EMPL_ID2
and CD1=cd2
AND desc1<>desc2
但這是給重複的結果。謝謝你的幫助!