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 the advantages of merge replication?
you added a row to a view, but the row is not shown on the view. Explain how this can happen, and how you can remedy the situation
How to access the inserted record of an event?
What is the difference between clustered and a non-clustered index?
What is importing utility?
What are the advantages of having an index on the sql server?
What is ddl command?
How to defragment indexes with alter index ... Reorganize?
Can you pass expressions to function parameters?
What is the architecture of ms sql reporting service?
What to perform pattern match with the like operator?
What does set rowcount do?
When would you use an insert into .. Select option versus an insert into .. Values option? Give an example of each?
Is the order of columns in the set clause important in ms sql server?
How to list all dsn entries on your local machine using odbc_data_source()?