compare 2 tables

I

Irina

Hello,
I was wondering if anyone can help me with this.
I want to compare 2 tables. One table has various fields such as employeeID,
date of hire and etc.. Scond Table has employeeID, family info.
I want to compare tbl2 to tbl1 and then add the employeeID's that are not
in tbl 2 into it from tbl 1.
thanks,
Irina
 
D

Douglas J. Steele

You can do this with a single query:

INSERT INTO Tbl2 (EmployeeID, Field1, Field2, Field3)
SELECT EmployeeID, Field1, Field2, Field3
FROM Tbl1
WHERE EmployeeID NOT IN
(SELECT DISTINCT EmployeeID FROM Tbl2)
 
G

Gus Chuch

You can do a query to find the missing ID’s
SELECT tbl1.ID
FROM tbl1 LEFT JOIN tbl2 ON tbl1.ID = tbl2.ID
WHERE (((tbl2.ID) Is Null));
And then you should be able to do a INSERT INTO query to add to the table

INSERT INTO tbl2 ( ID)
SELECT tbl1.ID
FROM tbl1 LEFT JOIN tbl2 ON tbl1.ID = tbl2.ID
WHERE (((tbl2.ID) Is Null));
see if this works for you
 

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