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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | 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
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

kwikwisi
Constraint Violating Yak Guru

282 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

3873 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  
 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.04 seconds. Powered By: Snitz Forums 2000