tags:

views:

315

answers:

2

I have two selects and I want to combine them in such a way, that only rows unique in both selects are returned. Is there any built-in way in Oracle 10g to achieve this?

I know I can do something like this:

(select1 UNION select2)
MINUS
(select1 INTERSECT select2)

but I would like to avoid it. Both select1 and select2 have 20 lines, so this way would be really obscure and difficult to maintain.

+2  A: 

If both select1 and select2 return no duplicates, you can use something like this:

SELECT * FROM (select1 UNION ALL select2) a
GROUP BY a.col1, a.col2, ...
HAVING count(*) = 1
Lukáš Lalinský
A: 

Here's another idea:

  • Do a full outer join of select1 and select2
  • Use only those records with select1.id = NULL (record is only in select2) or select2.ID = NULL (record is only in select1)

like this:

SELECT *
FROM select1 FULL OUTER JOIN select2 on select1.id = select2.id
WHERE select1.id is null or select2.id is null
IronGoofy