Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

oracle diff: how to compare two tables?

Tags:

diff

oracle

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?

like image 676
Mark Harrison Avatar asked Mar 27 '09 04:03

Mark Harrison


People also ask

How can I compare two columns in a table in Oracle?

Compare columns in two tables and list out column names which are different. for ex:- create table t1(c1 number(2), c2 varchar2(10)); create table t2(c1 number(2), c2 varchar2(10)); insert into t1 values(1,'a'); insert into t2 values(1,'b'); result should be column c2 is different.

How can I compare two tables in different columns in SQL?

Using joins to compare columns by priority among the table. For example, left join returns all values from the first table and null value for the not-matched records from the second table. Similarly, we can use right join, inner join, full join and self join as per our requirements.


2 Answers

Try this:

(select * from T1 minus select * from T2) -- all rows that are in T1 but not in T2 union all (select * from T2 minus select * from T1)  -- all rows that are in T2 but not in T1 ; 

No external tool. No performance issues with union all.

like image 191
L. Holanda Avatar answered Sep 22 '22 11:09

L. Holanda


You can try using set operations: MINUS and INTERSECT

See here for more details:
O'Reilly - Mastering Oracle SQL - Chapter 7 - Set Operations

like image 26
maxyfc Avatar answered Sep 23 '22 11:09

maxyfc