Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

How to retrieve duplicate rows in a table?
How to delete the duplicate entries in a table?

Answer Posted / skybeaver

/* selecting duplicate rows in a table */
select col1, col2, ..., colN, count(*)
from TableName
group by col1, col2, ..., colN
having count(*) > 1

/* deleting duplicate rows from a table */
select col1, col2, ..., colN, count(*) as "Duplicates"
into #duplicates
from TableName
group by col1, col2, ..., colN
having count(*) > 1

delete TableName
from TableName t, #duplicates d
where t.col1 = d.col1 and
....
t.colN = d.colN

/* damn I'm good! */

Is This Answer Correct ?    11 Yes 5 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What do we need queues in sql service broker?

1125


What are difference between Cluster index and Non-Cluster index?

1137


What is the difference between getdate and sysdatetime?

1067


You want to use a perspective in an mdx query. How do you select the perspective?

246


What are the types of joins in sql?

1173


List some case manipulation functions in sql?

1094


How to send a ssrs report from ssis?

184


How do you create a data source?

963


How to execute stored procedure and set temp table in sql server?

1101


Why variables called the most powerful component of ssis?

1130


Explain query editor regions

1115


Explain what is sql server english query?

1109


How many types of functions are there in sql server?

992


How to select true false based on column value in sql server?

1084


Can we insert data if clustered index is disabled?

989