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 to specify the collation for a character data type in ms sql server?
What is advantage data architect?
how can you attach more than 20 ldf files in sql server
How you can add messages to the nt event log from within a stored procedure?
How to start sql server browser service?
Can sql servers linked to other servers like oracle?
What is the difference between writing data to mirrored drives versus raid5 drives
What are the types of subquery?
What is the current limitation of the size of SQL Azure DB?
How to create dbo table in sql server?
How to delete an existing row with delete statements in ms sql server?
What is the difference between substr and charindex in the sql server?
what are candidate key, alternate key and composite key? : Sql server database administration
Explain what is cte (common table expression)?
What are the advantages of using third-party tools?