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
What are trace files?
Tell me what is the difference between locking and multi-versioning?
What are the results of running this script?
How to update a field in SQL after ALTERING a row?
What do you need to connect php to sql server?
What are the common performance issues in sql server?
Can you tell me some of the common replication dmv's and their use? : sql server replication
What happens when unicode strings concatenate with non-unicode strings?
Is the order of columns in the set clause important in ms sql server?
What are the limitations/drawbacks or ssrs 2008 r2?
What are the steps you will take to improve the performance of a poor performing query?
Can we join two tables without primary key?
What are various ways to enhance the ssrs report?
what is bit datatype? : Sql server database administration
Hi, I Created 3 Tables Person(PersID[prkey],Name,Email,Password), Project(ProjName,ProjID[prkey],ProjLeader,ProjManager) & ProjectInvolvement(EntryDate,ProjID[frkey],PersID[frkey],ProjDuration). For this how can i INSERT,UPDATE & DELETE Through PROCEDURE? Please Post the Answer for me. Desai.