SQL to find FileNum in one table not in another

G

Guest

I am now ready to start validating the data in my database. It's extracted
from several Excel Tables. One problem I'm encountering is that I need a
One-to-Many relationship between "EmpData" (One) and "CurrentData" (Many).
But I've got more records in "EmpData" than in "CurrentData" There needs to
be at least one record in "CurrentData" (715) for every record in "EmpData"
(734).

I've already run
SELECT COUNT (*) FROM eachtable
and
SELECT COUNT (DISTINCT *) FROM eachtable
to verify that there are no duplicates.

I'd like to build a query (preferably with SQL 'cuz I'm an old command-line
programmer who hates GUIs) that will find the records in "EmpData" without a
corresponding record in "CurrentData".

The PriKey in "EmpData" is FileNum. It is the relationship field (ForKey) in
"CurrentData".

Thanks for all your help!
 
J

John Spencer

To get records in EmpData that have no corresponding record in CurrentData

SELECT EmpData.*
FROM EMPData LEFT JOIN CurrentData
ON EmpData.FileNum = CurrentData.ForKey
WHERE CurrentData.ForKey is null



--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 
G

Guest

That returned the differing records. Thank you very much!
--
Adios,
Clay Harryman


John Spencer said:
To get records in EmpData that have no corresponding record in CurrentData

SELECT EmpData.*
FROM EMPData LEFT JOIN CurrentData
ON EmpData.FileNum = CurrentData.ForKey
WHERE CurrentData.ForKey is null



--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
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