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
Explain system functions or built-in functions? What are different types of system functions?
What is self contained sub query?
How to provide default values to function parameters?
How raid can influence database performance?
Can one drop a column from a table?
How do I find the sql server version?
What are the different SQL Server Versions you have worked on?
How to convert character strings into numeric values?
explain different types of backups avaialabe in sql server? Given a particular scenario, how would you go about choosing a backup plan? : Sql server database administration
How do I create a trace in sql server?
What are the pros and cons of putting a scalar function in a queries select list or in the where clause?
List out the different types of locks available in sql server?
Can you index views?
What is acid mean in sql server?
what is spatial nonclustered index