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

Explain how dts is used to extract, transform and consolidate data?

987


What will happen if a column containing char type data is changed to the nchar data type?

1091


What is nested transaction?

1091


What is difference between materialized view and view?

905


How to test odbc dsn connection settings?

1015


Can a table be created inside a trigger?

963


What is the minimum and maximum number of partitions required for a measure group? : sql server analysis services, ssas

1041


What are some of the pros and cons of not dropping the sql server builtinadministrators group? : sql server security

972


Explain Capacity planning to create a database? and how to monitor it?

4198


What are the different types of upgrades that can be performed in sql server?

1173


What are the recovery models in sql server 2000?

950


List the data types available in mssql?

1024


What is primary key and example?

936


What you can do to delete a table without the delete trigger firing?

963


sql database suspect We have a sql database that is showing as suspect. How can we recover?

1918