Append Query - must meet criteria

G

Guest

Hi all,
I am trying to create an append query to insert records in table 2 from data
in table 1, however, I only want it to work if a field value from table 1 is
not present in table 2. The field is called Item_ID in both table 1 and
table 2, however, I cannot get the query to work correctly... should i be
using an append query (as I do want to add new records) or should I pursue
another option?
Thanks!
-gary
 
M

Marshall Barton

Gary said:
I am trying to create an append query to insert records in table 2 from data
in table 1, however, I only want it to work if a field value from table 1 is
not present in table 2. The field is called Item_ID in both table 1 and
table 2, however, I cannot get the query to work correctly... should i be
using an append query (as I do want to add new records) or should I pursue
another option?


An Append query is the right thing to do:

INSERT INTO table2 (fielda, fieldb, . . .)
SELECT table1.fielda, table1.fieldb, . . .
FROM table1 LEFT JOIN table2
ON table1.key = tabl2.key
WHERE table2.key Is Null
 
J

John Spencer

Adding records is an append query. The SQL statement would look
something like:

INSERT INTO Table2 (FieldA, FieldB)
SELECT table1.FieldA, table1.FieldB
FROM Table1 LEFT JOIN Table2
ON Table1.ItemID = Table2.ITemID
WHERE Table2.ItemID is Null

You can create the unmatched query using the query wizard and then turn
that into an append query,
 
G

Guest

Thank you!!

John Spencer said:
Adding records is an append query. The SQL statement would look
something like:

INSERT INTO Table2 (FieldA, FieldB)
SELECT table1.FieldA, table1.FieldB
FROM Table1 LEFT JOIN Table2
ON Table1.ItemID = Table2.ITemID
WHERE Table2.ItemID is Null

You can create the unmatched query using the query wizard and then turn
that into an append query,
 
G

Guest

Thank you!!

Marshall Barton said:
An Append query is the right thing to do:

INSERT INTO table2 (fielda, fieldb, . . .)
SELECT table1.fielda, table1.fieldb, . . .
FROM table1 LEFT JOIN table2
ON table1.key = tabl2.key
WHERE table2.key Is Null
 

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