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

How to specify the collation for a character data type in ms sql server?

1015


What is advantage data architect?

910


how can you attach more than 20 ldf files in sql server

1990


How you can add messages to the nt event log from within a stored procedure?

1055


How to start sql server browser service?

1121


Can sql servers linked to other servers like oracle?

938


What is the difference between writing data to mirrored drives versus raid5 drives

914


What are the types of subquery?

1030


What is the current limitation of the size of SQL Azure DB?

124


How to create dbo table in sql server?

940


How to delete an existing row with delete statements in ms sql server?

1075


What is the difference between substr and charindex in the sql server?

1079


what are candidate key, alternate key and composite key? : Sql server database administration

903


Explain what is cte (common table expression)?

1117


What are the advantages of using third-party tools?

980