Solved

compare two tables from different databases with diferent column names

Posted on 2012-04-09
7
495 Views
Last Modified: 2012-05-01
Can any one help me out to compare the data between two tables where the tables are sitting on different databases with different columns

Ex:   'TB1' table in in 'DB1' sitting on server A,  with  'TB2' table in in 'DB2' sitting on server B
0
Comment
Question by:bhanu823
  • 4
  • 2
7 Comments
 
LVL 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 total points
ID: 37823815
try a minus query and database link:

select col1, col2 from DB1_table
minus
select colz, colx from DB2_table@serverB
/

Then the reverse:
select colz, colx from DB2_table@serverB
minus
select col1, col2 from DB1_table
/


alternative: spool the data to a text file form both tables and do a diff.
0
 

Author Comment

by:bhanu823
ID: 37823825
WHY DO WE NEED TO DO IT FOR  2 TIMES?.. NORMAL AND THEN REVERSE?
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 37823835
a Minus will also show 'missing' rows.  You need it twice for rows in one, not in the other and visa versa.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 31

Expert Comment

by:awking00
ID: 37823841
You say the column names are different, which is fine using minus, but you also need to be sure they are the same datatype and in the same order.
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 37823851
>>WHY DO WE NEED TO DO IT FOR  2 TIMES?..

Create a simple test case and see.    using the case below, if you only run it once you will not get the 'f' row.


drop table tab1 purge;
create table tab1(col1 char(1), col2 char(1));

drop table tab2 purge;
create table tab2(colz char(1), colx char(1));

insert into tab1 values('a','a');
insert into tab2 values('a','a');

insert into tab1 values('b','c');
insert into tab2 values('b','d');


insert into tab1 values('e','e');
insert into tab2 values('f','f');
commit;

select col1,col2 from tab1 minus select colz,colx from tab2;
select colz,colx from tab2 minus select col1,col2 from tab1;

Open in new window

0
 
LVL 31

Expert Comment

by:awking00
ID: 37823908
If you want to issue one query -
select col1, col2, ... from tab1
union all
select colz, colx, ... from tab2
minus
(select col1, col2, ... from tab1
 intersect
 select colz, colx, ... from tab2)
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 37823948
>>If you want to issue one query -

If you do this you will likely need to add some designator to determine what rows came from what side.

For example, using the example above:  Does 'e' not exist in DB1 or DB2?
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Article by: Swadhin
From the Oracle SQL Reference (http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries006.htm) we are told that a join is a query that combines rows from two or more tables, views, or materialized views. This article provides a glimps…
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now