Hi all,
hope someone can help! I have a query to look for duplicate records in our database. my duplicate query looks for any records that match on foename/surname/dob and ouptuts address details from the main table, then pulls out an extra reference from a 2nd table. My problem is that if a client has 2 or more child records in the 2nd table, the main record is coming out in the duplicate report, yet the record is not really a duplicate. I need to output any child records where they exist as they relate to who the client in the parent record is dealing with. What i need to do is prevent any parent records that have multiple child records from being returned UNLESS they do have a duplicate parent record in the main table. Sorry if im not making much sense/waffling...
here's my query:
In the query my main table is C, the duplicate is C2 and the child table is R
Many thanks
hope someone can help! I have a query to look for duplicate records in our database. my duplicate query looks for any records that match on foename/surname/dob and ouptuts address details from the main table, then pulls out an extra reference from a 2nd table. My problem is that if a client has 2 or more child records in the 2nd table, the main record is coming out in the duplicate report, yet the record is not really a duplicate. I need to output any child records where they exist as they relate to who the client in the parent record is dealing with. What i need to do is prevent any parent records that have multiple child records from being returned UNLESS they do have a duplicate parent record in the main table. Sorry if im not making much sense/waffling...
here's my query:
Code:
SELECT C.Client_Ref, C.Surname, C.NameFirst, C.DOB, C2.Client_Ref AS DupClientRef, C2.Surname AS DupClientSurname, C2.NameFirst AS DupClientNameFirst, C2.DOB AS DupClientDOB, C.AddSubDwelling, C.AddDwelling, C.AddStreet, C.AddLocality, C.AddTown, C.Postcode, R.TextRef
FROM C2 RIGHT OUTER JOIN
R RIGHT OUTER JOIN
C ON R.Client_Ref = C.Client_Ref ON C2.DOB = C.DOB AND
C2.NameFirst = C.NameFirst AND C2.Surname = C.Surname
WHERE C.DOB = C2_1.DOB
AND C.NameFirst = C2.NameFirst
AND C.Surname = C2.Surname
AND C.Client_Ref <> C2.Client_Ref
AND C.DateForDelete IS NULL
ORDER BY C.Surname, C.NameFirst, C.DOB
Many thanks