Click here to Skip to main content
13,625,609 members
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

71.2K views
27 bookmarked
Posted 26 Oct 2014
Licenced CPOL

Delete duplicate rows in SQL Server

, 26 Oct 2014
Rate this:
Please Sign up or sign in to vote.

Introduction

Some time some duplicate data may inserted in the SQL table. But its harmful for you and your application too. So how to remove the duplicate rows in your table.

Description

Take a look in the following table content. Its having duplicate rows.

Id       Name           Department

1        Arka               .NET

2        Ashok            .NET

3        Anubhav        php

4        Arka               .NET

5        Sucheta          Graphics

Row 1 and 4 are duplicate. So we have to remove one row and keep one in the table.

Now question is how to do?

Using the code

To solve this problem take a look at the following code. This will solve this problem.

WITH tblTemp as
(
SELECT ROW_NUMBER() Over(PARTITION BY Name,Department ORDER BY Name)
   As RowNumber,* FROM <table_name>
)
DELETE FROM tblTemp where RowNumber >1

After run these code show the table data, it will all unique rows present.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Arkadeep De
Software Developer Cognizant
India India
I am a Software developer having an experience of 4 years in application development. To get me you can mail me at arkadeepde@gmail.com or you can visit my blog at ASP With Arka

You may also be interested in...

Pro

Comments and Discussions

 
Praiseit's cool Pin
Ronald Luna Ramos30-Jan-18 2:35
memberRonald Luna Ramos30-Jan-18 2:35 
PraiseThank you, Thank you Pin
Ntingab5-May-16 4:04
memberNtingab5-May-16 4:04 
QuestionTHANKS Pin
Member 871442124-Jul-15 10:24
memberMember 871442124-Jul-15 10:24 
QuestionAnother simple solution Pin
govardhan4u29-Oct-14 6:18
membergovardhan4u29-Oct-14 6:18 
AnswerRe: Another simple solution Pin
Arkadeep De2-Nov-14 6:48
professionalArkadeep De2-Nov-14 6:48 
AnswerRe: Another simple solution Pin
aarif moh shaikh8-Mar-15 20:25
professionalaarif moh shaikh8-Mar-15 20:25 
QuestionDistinct keyword Pin
Member 889824828-Oct-14 22:17
memberMember 889824828-Oct-14 22:17 
AnswerRe: Distinct keyword Pin
Arkadeep De28-Oct-14 23:28
professionalArkadeep De28-Oct-14 23:28 
GeneralUNIQUE constraint? Pin
Gheorghe Musca28-Oct-14 21:15
memberGheorghe Musca28-Oct-14 21:15 
GeneralRe: UNIQUE constraint? Pin
Arkadeep De28-Oct-14 23:32
professionalArkadeep De28-Oct-14 23:32 
GeneralMy vote of 5 Pin
dmjm-h28-Oct-14 11:20
memberdmjm-h28-Oct-14 11:20 
GeneralRe: My vote of 5 Pin
Arkadeep De28-Oct-14 23:31
professionalArkadeep De28-Oct-14 23:31 
GeneralMy vote of 5 Pin
E. Scott McFadden28-Oct-14 8:33
professionalE. Scott McFadden28-Oct-14 8:33 
GeneralRe: My vote of 5 Pin
Arkadeep De28-Oct-14 23:30
professionalArkadeep De28-Oct-14 23:30 
QuestionVery nice. Pin
Member 1017996028-Oct-14 7:42
memberMember 1017996028-Oct-14 7:42 
AnswerRe: Very nice. Pin
Arkadeep De28-Oct-14 23:30
professionalArkadeep De28-Oct-14 23:30 
QuestionMy Vote of 5 Pin
Gopu Raj27-Oct-14 23:50
memberGopu Raj27-Oct-14 23:50 
AnswerRe: My Vote of 5 Pin
Arkadeep De28-Oct-14 0:55
professionalArkadeep De28-Oct-14 0:55 
GeneralRe: My Vote of 5 Pin
Gopu Raj28-Oct-14 1:15
memberGopu Raj28-Oct-14 1:15 
GeneralMy vote of 5 Pin
Humayun Kabir Mamun27-Oct-14 1:57
memberHumayun Kabir Mamun27-Oct-14 1:57 
GeneralRe: My vote of 5 Pin
Arkadeep De27-Oct-14 2:20
professionalArkadeep De27-Oct-14 2:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01 | 2.8.180712.1 | Last Updated 27 Oct 2014
Article Copyright 2014 by Arkadeep De
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid