Compare two SELECT statement using PL/SQL Developer

user5896972 picture user5896972 · Mar 29, 2016 · Viewed 10k times · Source

Suppose I have two SELECTquery on same table and I need to compare them column by column.

Query 1:

select * from mytable t1 where  t1.code = '100'

returns:

id           name
1            A
2            B

Query 2:

select * from mytable t2 where  t2.code = '999'

returns:

id           name
1            A
2            C

For my case both query returns same number of rows.

Desired result

id           name_t1     name_t2
2            B           C

How can I found the data difference between them using PL/SQL developer (better using tools to avoid query)?

My PL/SQL Developer Version 8.0.3.1510

Answer

Ramki picture Ramki · Mar 29, 2016

you can use MINUS

select * from mytable t1 where  t1.code = '100'

MINUS 
select * from mytable t2 where  t2.code = '999';

MINUS gives you the rows that are found in the first query and not in the second query by removing from the results all the rows that are found only in the second query