I’m trying to remove duplicates records ids keeping the max date and deleting the min.
Delete from mytable
where id=(select a.id, MIN(CONVERT(varchar(12),a.dates,101)) from mytable as a where a.id=mytable.id
and id IN(select id, count(*) rcrds from mytable group by id HAVING count(id) >1 ) group by a.id)
Delete from mytable
where id=(select a.id, MIN(CONVERT(varchar(12),a.dates,101)) from mytable as a where a.id=mytable.id
and id IN(select id, count(*) rcrds from mytable group by id HAVING count(id) >1 ) group by a.id)