Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compare data in multiple tables

Status
Not open for further replies.

sheed

Programmer
Jun 14, 2005
38
0
0
US
I have 4 tables with 4 columns each that hold the same data 99% of the time. But there might be some data inconsistency in those tables i.e. some data missing in some tables or sometimes some columns having inconsistent data. How can I compare the records in these 4 tables and see what data or records are missing and what data is inconsistent in what tables and extract the inconsistent records. Can someone please help how to can I compare this using PL/SQL, as I am new to this and am trying to figure out. Thanks for any help.
 
Sheed,

By far, the fastest, most-efficient method of isolating unique records from your four tables is:
Code:
prompt Rows unique to Table 1:
select * from tab1
minus
(select * from tab2
 union
 select * from tab3
 union
 select * from tab4);
prompt
prompt Rows unique to Table 2:
select * from tab2
minus
(select * from tab1
 union
 select * from tab3
 union
 select * from tab4);
prompt
prompt Rows unique to Table 3:
select * from tab3
minus
(select * from tab1
 union
 select * from tab2
 union
 select * from tab4);
prompt
prompt Rows unique to Table 4:
select * from tab4
minus
(select * from tab1
 union
 select * from tab2
 union
 select * from tab3);
Let us know if you like what you see.



[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[ Providing low-cost remote Database Admin services]
Click here to join Utah Oracle Users Group on Tek-Tips if you use Oracle in Utah USA.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top