SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Delete duplicate records
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

kwikwisi
Constraint Violating Yak Guru

280 Posts

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

Thanks

James K
Flowing Fount of Yak Knowledge

3699 Posts

Posted - 05/04/2014 :  21:42:22  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000