I want to check if there are duplicates in my table ParticipantsDebtor, duplication is compared to Name, ParticipantsCode and DateOfBirth the Name and ParticipantsCode field is in the ParticipantsDebtor table and DateOfBirth is in ParticipantDebtorDetail table, my request turns into the void I do not know if this is correct but very long or it is false
Table ParticipantsDebtor has:
- DebtorId
- Name
- ParticipantsCode
Table ParticipantDebtorDetail has:
- DebtorId
- DateOfBirth
Query:
SELECT a.ParticipantCode, a.Name, COUNT(a.DebtorId) AS DuplicateNumber, b.DateOfBirth FROM ParticipantDebtors a WITH (NOLOCK), crem.ParticipantDebtorDetail b WITH (NOLOCK) WHERE a.DebtorId <> b.DebtorId GROUP BY a.ParticipantCode, a.Name, b.DateOfBirth HAVING COUNT(a.DebtorId) > 1