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 you would rewrite the sql query to return the customerid sorted numerically?

936


What are the events recorded in a transaction log?

930


What is application role in sql server database security? : sql server security

993


How do I get Report Builder to generate a parameter that can be set by users viewing the report?

139


What are trace files?

894


What is the web service used for reporting services?

114


What is normalization and what are the advantages of it?

921


What happens to a trigger with multiple affected rows?

865


What are dml triggers and types of dml triggers?

921


How do I uninstall sql server 2014?

873


Does index slows down insert statements?

936


Explain syntax for viewing, dropping and disabling triggers?

897


What are subqueries in sql server? Explain its properties.

965


last function used in MS Access to convert sql what function will use in sql

2017


Explain user defined functions?

946