Append only when the records don't already exist

T

Tara

I must be having a low brain-function moment here, but for the life of me, I
can't figure this out.

Here's the deal: I want to look at one table to see if certain records
exist and I want to compare that to the records that exist in another table.
If there are records in table 2 that are not in table 1, I want those records
to append to table 1. For example. Employee John Doe is listed (via an ID
number) in table 1 and in table 2. Employee Tom Smith is listed (via an ID
number) in table 2 but not in table 1. I want Tom Smith's ID number to
append to table 1, but not John Doe's since his already exists.

I'm going to feel really dumb when I get a response to this, I know. It
should be so simple. But like I said, I'm not having the greatest day and I
think my brain is on strike.

Any help is appreciated.
 
J

John Spencer

INSERT INTO Table1 (<<LIST OF FIELDS>>)
SELECT <<List of Fields in Table2>>
FROM Table2 LEFT JOIN Table1
ON Table2.ID = Table1.ID
WHERE Table1.ID is NULL

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
 

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