Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Delete duplicate records

Author  Topic 

kwikwisi
Constraint Violating Yak Guru

283 Posts

Posted - 2014-05-04 : 13:46:38
Is it possible to delete duplicate records on group by a column, take record with latest modifiedOn date ?

Thanks

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2014-05-04 : 21:42:22
Yes.
;with cte as
(
select
row_number() over (partition by theColumn order by ModificationDate desc) as RN
from
YourTable
) delete cte where RN > 1;
Go to Top of Page
   

- Advertisement -