PDA

View Full Version : Continuing trouble with LEFT JOINs



mud2
04-06-2006, 05:29 PM
Two tables:
KeyTable, has one column called LKey,
ParsedTable has one column called RightKey
Neither table is empty.
I want to add to Keytable those records in ParsedTable that are NOT in KeyTable.

I(Try) use
INSERT INTO KeyTable SELECT ParsedTable.RightKey FROM ParsedTable
LEFT JOIN KeyTable ON
ParsedTable.RightKey = KeyTable.LKey WHERE KeyTable.LKey IS NULL.

ACCESS DoCmd.RunSql insists it can't find RightKey
An ACCESS FORM has no trouble.

The sample given to me in an earlier answer works, but I just can't seem to translate it to my needs.

I'm about to punt, and use something that makes sense, like VBA, opening two recordsets, and comparing them.

matthewspatrick
04-07-2006, 06:07 AM
Two tables:
KeyTable, has one column called LKey,
ParsedTable has one column called RightKey
Neither table is empty.
I want to add to Keytable those records in ParsedTable that are NOT in KeyTable.

Try this:


DoCmd.RunSQL "INSERT INTO KeyTable " & _
"SELECT ParsedTable.RightKey " & _
"FROM ParsedTable " & _
"WHERE ParsedTable.RightKey NOT IN " & _
"(SELECT KeyTable.LKey FROM KeyTable)"