Write a query to delete duplicate records in SQL SERVER
Answer Posted / ben mccameron
I have a query that I use with success I have a table with
telephone numbers in it and sometimes I have duplicate
phone numbers in the table... here is how I see what they
are and then remove them.
===========================================
select telephone
from Table_A
group by telephone having count(*) > 1
SET ROWCOUNT 1
SELECT NULL
WHILE @@rowcount > 0
DELETE step
FROM Table_A as step
INNER JOIN
(SELECT telephone
FROM Table_A
GROUP BY telephone HAVING count(*) > 1)
AS t ON t.telephone = step.telephone
SET ROWCOUNT 0
===========================================
This query will actually find and remove the duplicates
from Table_A but will not remove both instances it will
only remove one... leaving you with one good record... hope
this helps someone. : )
| Is This Answer Correct ? | 11 Yes | 3 No |
Post New Answer View All Answers
What is the function of inner join?
What is raiseerror? What is raiseerror?
Can I use sql azure as a backup with log shipping or database mirroring?
How can you find out which stored procedures are recompiling?
What is the dbcc command and why is it used?
what is the difference between Tabular and Matrix report?
When would you prefer to have a minimum number of indexes?
Can you leave a union at any time?
Is the primary key column of a table an index in ms sql server?
Why does sql studio use a single registered database repository? : sql server management studio
Which sql server is best?
How to run sql server 2005 books online on your local system?
What are the requirements to use odbc connections in php scripts?
How to test a dml trigger in ms sql server?
Why main is user defined function?