How to delete duplicate records from oldest the newest without a timestamp and GUID
as Primary Key
?
- eg, if I have 4 records, delete the oldest 3 based of the GUID
This is as far as I have got,
WITH cte
AS(SELECT ID, ROW_NUMBER() OVER(PARTITION BY CodeOne, CodeTwo
ORDER BY(SELECT 0)) RN
FROM [InvoiceDatabase].[dbo].[LookUpCode])
DELETE FROM cte
WHERE RN > 1;
But this is not doing what I need, although is deleting duplicates correctly. Is there a way doing this or is it impossible to use a GUID
to tell which record is older?