compare two tables from different databases with diferent column names

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
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

slightwv (䄆 Netminder) Commented:
try a minus query and database link:

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

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

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bhanu823Author Commented:
slightwv (䄆 Netminder) Commented:
a Minus will also show 'missing' rows.  You need it twice for rows in one, not in the other and visa versa.
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

awking00Information Technology SpecialistCommented:
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.
slightwv (䄆 Netminder) Commented:

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');

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

awking00Information Technology SpecialistCommented:
If you want to issue one query -
select col1, col2, ... from tab1
union all
select colz, colx, ... from tab2
(select col1, col2, ... from tab1
 select colz, colx, ... from tab2)
slightwv (䄆 Netminder) Commented:
>>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?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.