reconcile related tables

C

CuriousMark

I have two similar tables. The second table was created from the first and
then had data modified. I need to update the first table with the modified
table. I can't figure out to uniquely identify the records for updating
because the record IDs were not copied between the tables. The table
structures are like this:

Table1

LastName, FirstName, FieldA, FieldB, FieldC

Table2

LastName, FirstName, FieldA, FieldB, FieldD

How can I update FieldA and FieldB in Table1 with data from Table2 if the
data has changed, and add FieldD to Table1, matching the LastName and
FirstName?

Thanks very much.
 
K

KARL DEWEY

Add FieldD to Table1. Backup the database.
Try this update query --
UPDATE Table1 INNER JOIN Table2 ON Table1.LastName = Table2.LastName AND
Table1.FirstName = Table2.FirstName SET Table1.FieldA = Table2.FieldA,
Table1.FieldB = Table2.FieldB, Table1.FieldD = Table2.FieldD;
 
C

CuriousMark

Thanks very much Karl. Worked perfectly. But that brought another problem:
There are records in Table2 that are not in Table1. How do I append those
records to Table1? How do I write a query that will identify the records in
Table2 that are not in Table1?
 

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

Similar Threads


Top