Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

Explain the advantages of merge replication?

955


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

947


How to access the inserted record of an event?

1051


What is the difference between clustered and a non-clustered index?

1033


What is importing utility?

993


What are the advantages of having an index on the sql server?

925


What is ddl command?

987


How to defragment indexes with alter index ... Reorganize?

1089


Can you pass expressions to function parameters?

1107


What is the architecture of ms sql reporting service?

988


What to perform pattern match with the like operator?

886


What does set rowcount do?

913


When would you use an insert into .. Select option versus an insert into .. Values option? Give an example of each?

1113


Is the order of columns in the set clause important in ms sql server?

973


How to list all dsn entries on your local machine using odbc_data_source()?

1042