Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Finding Difference between Two Tables.

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-04-22 : 09:05:37
Arshad writes "Hello,

I have one question about finding out difference between two tables. For example Table A & Table B.

The primary key in both the tables consists of three columns (product ID, Country Code and Price Code). And I want to find the following things,

1. Deleted Records(Records present in Table A and not in Table B)
2. New Records(Records present in Table B and not in Table A)
3. Changed Records(Records presents in both the table but with changed data)

I tried with left outer joins but couln't get the exact data. For example I tried left outer join to get all those records in Table A but not in Table B. I know non-matching rows are 10,000 in Table A, so I should get only 10,000 rows but I get all those rows from Table A which are non-matched because of left outer join.

I tried equi-joins too on both the tables to find out differences but this takes plenty of time and hence I can't implement this.

Could anybody of you let me now how should I tackle this problem.

Cheers,
Arshad"

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2002-04-22 : 10:03:05



This looks like a job for

The Outer Join

Is it a bird ? Is it a plane ?

No, it's an outer join (or FULL OUTER JOIN), think of it as a left and a right join at the same time.

It will replace not matching rows on each side of the join with NULLs as a left outer join.

Hope that answer is as much fun as I had writing it

Damian
Go to Top of Page

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2002-04-22 : 10:20:42
or if you are willing to pay a small fee (and available on a trial basis).....


have a look at www.red-gate.com

they sell SQL database comparison software....

it'll compare both data and structures....


Go to Top of Page
   

- Advertisement -