Good afternoon, I've been searching and can't really find a solution. I have inherited a database and queries and procedures, one of which identifies duplicates in one field that requires me to keep the latest & delete other lines. So I thought that by creating some sort of ranking would help. At the moment I have the following SELECT statement that displays the duplicates and I have to manually delete the unwanted lines:
I had a thought that, at the very least, I would be able to sort the results by this ranking column and delete all those that weren't ranked as a 1.
Any assistance of how I could do this a lot smarter would be gratefully received.
Many thanks,
D€$
Code:
SELECT MPI.NHSNO, MPI.ORG, MPI.DOB, MPI.SEX, MPI.ETHNIC, MPI.VETERAN, MPI.GPCD, MPI.POSTCODE, MPI.Date
FROM MPI
WHERE (((MPI.NHSNO) In (SELECT [NHSNO] FROM [MPI] As Tmp GROUP BY [NHSNO],[ORG] HAVING Count(*)>1 And [ORG] = [MPI].[ORG])))
ORDER BY MPI.NHSNO, MPI.Date DESC;
I had a thought that, at the very least, I would be able to sort the results by this ranking column and delete all those that weren't ranked as a 1.
Any assistance of how I could do this a lot smarter would be gratefully received.
Many thanks,
D€$