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
You have developed an application which uses many stored procedures and triggers to update various tables users ocassionally get locking problems which tool is best suited to help you diagnose the problem?
explain different types of backups avaialabe in sql server? : Sql server database administration
after migrating the dts packg to ssis by using migrtn wizrd in 2005. iam not able to open ssis pack and getting error. what r those errors? how to resolve?
explain different types of joins? : Sql server database administration
Can we use custom code in ssrs?
How do I create a partition table in sql server?
What is de-normalization in sql database administration? Give examples?
What is partition, how will you implement it? : sql server analysis services, ssas
You want to generate a report that is formatted as a chart. Can you use the report wizard to create such a report?
Does an index slow down updates on indexed columns?
wat wil hapn if we give the both read and deny read permission to user?
1 01 101 01010
How to update muliple row in single query?
How to use “drop” keyword in sql server and give an example?
Can you type more than one query in the query editor screen at the same time?