unmatched query comparing 2 fields

BobSullivan
3StarLounger
Posts: 235
Joined: 08 Jun 2010, 20:03
Location: Morgantown, PA

unmatched query comparing 2 fields

Post by BobSullivan »

I need to move records into a table when a person has not attended a training class,
I have two tables:
TblNewList contains
EmpName
TrainingClass
EmpID
and other fields

TblNCList contains
EmpID
TrainingClass
EmpName
and other fields

So if the ID and the class don't already exist in the receiving table, I want to add the record.
I want to run a query that appends records from the tblNewList to the tblNCList where the combination of EmpID and TrainingClass are not already in the tblNCList. If it was only one field, I created a simple find unmatched query on ID, then added the TrainingClass field. But when I add the second field to the SQL statement, it doubles the number of output records by duplicating each one. Probably an easy fix, but I thought I'd ask. Here's the current SQL code:

Code: Select all

INSERT INTO tblNCList ( UserName, TrainingClass, EmpID, MemCont )
SELECT tblNewList.EmpName, tblNewList.TrainingClass, tblNewList.EmpID, tblNewList.MemCont
FROM tblNewList LEFT JOIN tblNCList ON (tblNewList.[TrainingClass] = tblNCList.[TrainingClass]) AND (tblNewList.[EmpID] = tblNCList.[EmpID])
WHERE (((tblNCList.EmpID) Is Null));
I added the part after the AND statement.

Thanks!
Cordially,

Bob Sullivan
Elverson, PA

User avatar
HansV
Administrator
Posts: 78589
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: unmatched query comparing 2 fields

Post by HansV »

I cannot reproduce the problem. Are you sure that tblNewList doesn't contain duplicate records?
Best wishes,
Hans

BobSullivan
3StarLounger
Posts: 235
Joined: 08 Jun 2010, 20:03
Location: Morgantown, PA

Re: unmatched query comparing 2 fields

Post by BobSullivan »

:scratch: Yep. I was appending to the wrong table. Sorry.
Cordially,

Bob Sullivan
Elverson, PA