Reputation: 116
I have two different tables like this...
TblDepartment : DeptId, DeptName
TblEmployee : EmpId, DeptId, DeptName
Now due to some error there are some wrong mappings in employee table of deptId and deptName (DeptName mapped with wrong DeptId)
I want to figure out those DeptIds...
Any help will be appreciated...
Upvotes: 0
Views: 97
Reputation: 56
one of the best solutions for comparing two tables is using checksum like the below link :
https://www.red-gate.com/simple-talk/sql/t-sql-programming/on-comparing-tables-in-sql-server/
Upvotes: 1
Reputation: 164064
Use NOT EXISTS
to get all the employees for which their DeptId
and DeptName
do not match (both) a department:
SELECT e.*
FROM TblEmployee e
WHERE NOT EXISTS (
SELECT 1
FROM TblDepartment d
WHERE d.DeptId = e.DeptId AND d.DeptName = e.DeptName
)
Upvotes: 1