Join Dotnetcodes DotnetCodes.com is online Discussion Forum for Software professionals . It lets you find friends around the world and Create professional network that share similar interests as you. Get help on ur projects by industry specialists. Also get answers to all ur technical/placement related querries.Get an edge over others.
Already MemberClick here to login
ASP.net MVC Interview Questions Answers Interview Questions
Get Started Developing for Android Apps with Eclipse Articles
Serial Number in SSRS Articles
.Net framework 4.0 Interview Questions Answers Interview Questions
SQL server reporting services Interview Questions (SSRS) part 1 Articles
Whats New in ASP.NET 4.0 Part 2 Articles
How to Print a Crystal Report direct to printer Articles
Difference between Encapsulation and Abstraction Interview Questions
Explaining SDLC -System Development Life Cycle Articles
Html5 interview questions and answers Interview Questions
SharePoint 2010 interview Questions Answers Interview Questions
Infosys Interview Questions Interview Questions
Dynamic Menu using HTML List Tag and CSS in ASP.Net Articles
Populate or bind Dropdownlist in Asp.net using Jquery and Json Articles
ASP.NET MVC Overview Interview Questions
Submit Articles | More Articles..

Deleting Duplicate rows from a table

Posted By: [email protected] On:7/14/2010 1:50:14 AM in:Source Codes Category:Sql Server Hits:1832
Suppose I have a table named Emp I have different records in it. There may be some duplicate rows in this table. I want to delete all duplicate rows in one shot. In such a scenario the following code will be helpful:

 

 

 

/* First of all check whether the table has record or not */

 

1.      Select * from Emp;

 

2.      With temp as (Select row_number() over (order by column1, column2, column3) as row, column1, column2, column3 from Emp);

 

/* Now we will Delete the rows which are duplicates */

 

3.      Delete from temp where row not in (select row from (select column1, column2, column3, MIN(row)

row

from temp a

group by column1, column2, column3) b);

 

/*Now again check the table */

 

4.      Select * from Emp;

 

Hurrah!!!!!!!! All duplicate rows has been deleted!!!!!!!!!!

 

 

Hope it will help you��..

 

Have a nice day�

comments powered by Disqus
User Profile
Piyush Kumar
.Net Programmer
New Delhi , India
Email :You must Log In to access the contact details.
Latest Post from :[email protected]
Normalization
View: 1294 | Submitted on: 7/28/2010 11:37:14 PM
What is MVC?
View: 1324 | Submitted on: 7/26/2010 5:02:22 AM
Deleting Duplicate rows from a table
View: 1832 | Submitted on: 7/14/2010 1:50:14 AM
How To convert a Number into Word
View: 3430 | Submitted on: 7/14/2010 12:50:25 AM
Serial Number in SSRS
View: 12935 | Submitted on: 7/12/2010 6:25:55 AM
Submit Articles | All Post of This User..

All rights reserved to dotnetcodes. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks.
Best viewed at 1024 x 768 resolution with Internet Explorer 5.0 or Mozila Firefox 3.5 or Google Crome and higher