开发者

Oracle sql worksheet

I'm trying to compare 2 columns and the goal is the return of the lines that don't match. For example I have in column 1 and 2 the following

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

the return I'm looking for is

2  ccc 22  ddd
2  ccc 22  eee 

I'm trying to use the following

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

I get the following error

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

That refers to the line with the 1st (

Any help would be very appreciated.


The specific error you are getting is because of the following:

where id in ( select id, name, age from

You can not use an in clause to compare a single value of ID to 3 other values.

-- 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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜