Suppose I have two tables, t1 and t2 which are identical in layout but which may contain different data.
What\'s the best way to diff these two tables?
You may try dbForge Data Compare for Oracle, a **free GUI tool for data comparison and synchronization, that can do these actions over all database or partially.
For this kind of question I think you have to be very specific about what you are looking for, as there are many ways of interpreting it and many different approaches. Some approaches are going to be too big a hammer if your question does not warrant it.
At the simplest level, there is "Is the table data exactly the same or not?", which you might attempt to answer with a simple count comparison before moving on to anything more complex.
At the other end of the scale there is "show me the rows from each table for which there is not an equivalent row in the other table" or "show me where rows have the same identifying key but different data values".
If you actually want to sync Table A with Table B then that might be relatively straightforward, using a MERGE command.
Try This,
alter session set "_convert_set_to_join"= true;
The other alternative is to rewrite the SQL query manually [replacing the minus operator with a NOT IN subquery] evidences about 30% improvement in execution time .
select *
from A
where (col1,col2,?) not in
(select col1,col2,? from B)
union all
select * from B
where (col1,col2,?) not in
(select col1,col2,? from A);
I have referred from this post click here
Fast solution:
SELECT * FROM TABLE1
MINUS
SELECT * FROM TABLE2
No records should show...
Try:
select distinct T1.id
from TABLE1 T1
where not exists (select distinct T2.id
from TABLE2 T2
where T2.id = T1.id)
With sql oracle 11g+
You can try using set operations: MINUS
and INTERSECT
See here for more details:
O'Reilly - Mastering Oracle SQL - Chapter 7 - Set Operations