Cycle Through two Tables

D

Dominic

Hi

I have two tables with similar data in them and i want to
be able to build a list by doing the following

from table1 find records that are in table2 and add them
to the table1 and then do the cycle again until it doesn't
find any more records related in table2

Does anyone know the best way to do this

Thanks in advance
 
J

John Viescas

You can do it with a single Append query. The general technique is:

INSERT INTO Table1
SELECT Table2.*
FROM Table2 LEFT JOIN Table1
ON Table2.Key = Table1.Key
WHERE Table1.Key IS NULL

--
John Viescas, author
"Microsoft Office Access 2003 Inside Out"
"Running Microsoft Access 2000"
"SQL Queries for Mere Mortals"
http://www.viescas.com/
(Microsoft Access MVP since 1993)
 
Top