2

So I got two sets of tables at work that I have to compare the data. The fields are identical, but there is no column that has unique entries. (Employee ID, Assignment ID, Employee's last name, Employee's First Name, Dependent Last name, Dependent First name, Dependent Date of Birth) An employee can have multiple assignments, and each employee can have multiple dependents.

The data of the two tables were entered by different people and so they are messy.. and I was asked to do some data cleanup. Some of the dependents can be missing for an employee, or the dependent's name is spelled wrong /blanks etc...

Is there a way to compare the two tables for unmatched records, so that I can create a table for all data?

I tried to use Find Unmatched Fields query in Access but it can only compare one field?

Thanks in advance!:)

==edit==

I'm adding some sample data here:

enter image description here

vpxoxo
  • 121
  • 1
  • 3

1 Answers1

1

this is a start

select table1.*, table2.*
from table1 
full outer join table2 
 on table1.EmployeeID   = table2.EmployeeID 
and table1.AssignmentID = table2.AssignmentID 
where table1.EmployeeID is null or table2.EmployeeID is null 
order by isnull(table1.EmployeeID, table2.EmployeeID) 

But that order by may break the outer so if you get no rows remove it

Note this data does not appear to be properly normalized. This would allow for the same EmployeeID with different name. It is odd that dependent is dependent on assignmentID. If you are going to clean it up then consider improving the data design.

Pick one to fix (add missing data) in the case table1

Then go after data the does not match

select t1.*, t2.*
from table1 t1 
join table2 t2
  on t1.EmployeeID   = t2.EmployeeID 
 and t1.AssignmentID = t2.AssignmentID 
 and (    t1.DependentLastName <  t2.DependentLastName 
       or t1.DependentLastName is null 
       or t2.DependentLastName is null )
left table2 t2b 
  on t1.EmployeeID        = t2b.EmployeeID 
 and t1.AssignmentID      = t2b.AssignmentID 
 and t1.DependentLastName = t2b.DependentLastName
where t2b.EmployeeID is null  
paparazzo
  • 5,048
  • 1
  • 19
  • 32