2011-08-10 16 views
0

2つの列を比較しようとしていますが、目標は一致しない行の戻り値です。たとえば、私はOracle sqlワークシート

1      2 
id name age job  id name age job 
1 aaa 11 bbb  1 aaa 11 bbb 
2 ccc 22 ddd  2 ccc 22 eee 

次の列1と2を持っている私が探しているリターンは、私は私が手に、次の

select id, name, age from 1 where id in 
(
select id, name, age from 1 
minus 
select id, name, age from 2 
) 
union all 
select id, name, age from 2 where id in 
(
select id, name, age from 1 
minus 
select id, name, age from 2 
) 
order by id 

を使用しようとしている

2 ccc 22 ddd 
2 ccc 22 eee 

です次のエラー

ORA-00913: demasiados valores 
00913. 00000 - "too many values" 
*Cause:  
*Action: 
Error at Line: 6 Column: 1 

Tha tは1番目の行を指します(

ご協力いただければ幸いです。

答えて

5

あなたが取得している特定のエラーは、次のものです:あなたは3つの他の値にIDの単一の値を比較するために、句で使用することはできません

where id in (select id, name, age from 

-- get values in 1 not in 2 
SELECT 1.id, 1.name, 1.age 
FROM 1 
LEFT JOIN 2 on 1.id = 2.id and 1.name = 2.name and 1.age = 2.age 
WHERE 2.id is null 
UNION 
-- get values in 2 not in 1 
SELECT 2.id, 2.name, 2.age 
FROM 2 
LEFT JOIN 1 on 2.id = 1.id and 2.name = 1.name and 2.age = 1.age 
WHERE 1.id is null 
+0

は私がやったあなたのポスト に似た '( が2から1を引い選択*から*を選択した) 組合すべて (1から* 2、マイナスの選択から選択*)' と私が望んだことをexacly work thxあなたの時間のために –

+0

これは、他のシステムへの移植性の高いSQL賢明なので、私は左のアンチ・ジョイント・パターンを選択しましたが、オラクルのマイナスは、 – Andrew