.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> Sql Server >> Post New QuestionBookmark and Share Subscribe to Forum

delete duplicate recotds in sql

Posted By: yogesh tiwari     Posted Date: November 03, 2011    Points:5   Category :Sql Server
how to delete duplicate records in sql.

thanks

yogesh

Responses
Author: Cheta             
Posted Date: November 03, 2011     Points: 20   

Suppose we have the situation to delete some duplicate records in our table. Suppose consider one table

create table #Test
(
EmpID int,
EmpName varchar(50)
)

-Insert the Records into #Test table

insert into #Test values(1,'Daya')
insert into #Test values(1,'Daya')
insert into #Test values(1,'Daya')

Now i have two duplicate records inserted and i want to delete those records. The following query will delete the duplicate records

-Query to Delete Duplicate Records

WITH Emp AS (SELECT ROW_NUMBER ( ) OVER ( PARTITION BY EmpID, EmpName ORDER BY EmpID ) AS RNUM FROM #Test )
DELETE FROM Emp WHERE RNUM > 1



Author: Akhil Raj       [Moderator]      
Posted Date: November 04, 2011     Points: 20   

Read the following articles

http://support.microsoft.com/kb/139444
http://www.4guysfromrolla.com/ASPScripts/PrintPage.asp?REF=%2Fwebtech%2Fsqlguru%2Fq051200-2.shtml
http://blog.sqlauthority.com/2007/03/01/sql-server-delete-duplicate-records-rows/



Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend