How Do I compare differences between the data in two tables?

G

Guest

I am trying to create a Diff (or Delta) query that will return only data that
is different between two tables. All the fields are identical between the
two tables and I am using a field such as SSN as the primary key. I want a
query to return a line if Joe Schmoe's address is different in one table from
the next, or if Jane Doe exists in the new table but not the old (added), or
if John Doe exists in the old table but not the new (deleted).
 
R

Rick B

If the structure is identical, why do you have two tables? I'd recommend
normalizing your design before you go any further.
 
S

SusanC

I have a similar problems where the structure isn't identical. Then
how do you do it?
 
R

Rick B

If the structure is different, then what are you comparing?

You must have some similar fields in the tables that you wish to compare.

Details please...
 
V

Vincent Johns

Matt said:
I am trying to create a Diff (or Delta) query that will return only data that
is different between two tables. All the fields are identical between the
two tables and I am using a field such as SSN as the primary key. I want a
query to return a line if Joe Schmoe's address is different in one table from
the next, or if Jane Doe exists in the new table but not the old (added), or
if John Doe exists in the old table but not the new (deleted).


The "Find Unmatched Query Wizard" will give you the (added) and
(deleted) lists, though you'll have to use it twice, once for each
Table. For differences between records that are present in both copies,
use something like this:

SELECT Copy1.Address, Copy2.Address
FROM Copy1 INNER JOIN Copy2
ON Copy1.SSAN = Copy2.SSAN
WHERE (((Copy2.Address)<>[Copy1].[Address]))
ORDER BY Copy1.Address;


-- Vincent Johns <[email protected]>
Please feel free to quote anything I say here.
 
G

Guest

Vincent:

Thanks. It has been a while since I posted my question and have since found
a workaround. Very similary to what you suggested: 3 queries that are then
joined together by a 4th (make table query).

Matt


Vincent Johns said:
Matt said:
I am trying to create a Diff (or Delta) query that will return only data that
is different between two tables. All the fields are identical between the
two tables and I am using a field such as SSN as the primary key. I want a
query to return a line if Joe Schmoe's address is different in one table from
the next, or if Jane Doe exists in the new table but not the old (added), or
if John Doe exists in the old table but not the new (deleted).


The "Find Unmatched Query Wizard" will give you the (added) and
(deleted) lists, though you'll have to use it twice, once for each
Table. For differences between records that are present in both copies,
use something like this:

SELECT Copy1.Address, Copy2.Address
FROM Copy1 INNER JOIN Copy2
ON Copy1.SSAN = Copy2.SSAN
WHERE (((Copy2.Address)<>[Copy1].[Address]))
ORDER BY Copy1.Address;


-- Vincent Johns <[email protected]>
Please feel free to quote anything I say here.
 
V

Vincent Johns

Matt said:
Vincent:

Thanks. It has been a while since I posted my question and have since found
a workaround. Very similary to what you suggested: 3 queries that are then
joined together by a 4th (make table query).

Matt

Well, I hope I helped. I'm happy you found a solution. It may have
taken some time, but my guess is that, now that you've solved it, this
kind of problem won't give you much trouble in the future.

-- Vincent Johns <[email protected]>
Please feel free to quote anything I say here.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top