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
How you would rewrite the sql query to return the customerid sorted numerically?
What are the events recorded in a transaction log?
What is application role in sql server database security? : sql server security
How do I get Report Builder to generate a parameter that can be set by users viewing the report?
What are trace files?
What is the web service used for reporting services?
What is normalization and what are the advantages of it?
What happens to a trigger with multiple affected rows?
What are dml triggers and types of dml triggers?
How do I uninstall sql server 2014?
Does index slows down insert statements?
Explain syntax for viewing, dropping and disabling triggers?
What are subqueries in sql server? Explain its properties.
last function used in MS Access to convert sql what function will use in sql
Explain user defined functions?