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...

Please give me queries for the following
1. To get the count of duplicate records.
2. A query to delete the duplicate records.

Answer Posted / srikanth

1. use group by clause with the field on which you want to
check for duplicates

Ex: select salary,count (*) from employee group by salary
having count (*)>1

2. Use the below query to delete the duplicate records (not
the original ones)

SET ROWCOUNT 1
DELETE yourtable
FROM yourtable a
WHERE (SELECT COUNT(*) FROM yourtable b WHERE b.name1 =
a.name1 AND b.age1 = a.age1) > 1
WHILE @@rowcount > 0
DELETE yourtable
FROM yourtable a
WHERE (SELECT COUNT(*) FROM yourtable b WHERE b.name1 =
a.name1 AND b.age1 = a.age1) > 1
SET ROWCOUNT 0

Is This Answer Correct ?    5 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What does the on update no action do?

1034


What is the primary use of the model database?

1095


What is the new security features added in sql server 2014? : sql server security

1011


Can we perform backup restore operation on tempdb?

1028


What is the difference between varchar and nvarchar datatypes?

1093


What is a View ? Can we insert, Update and delete a view?

1001


What are the five characteristics of good data?

923


How you can move data or databases between servers and databases in sql server?

1058


You are designing a database for your human resources department in the employee table, there is a field for social security number, which cannot contain null values if no value is given, you want a value of unknown to be inserted in this field what is the best approach?

1109


How real and float literal values are rounded?

1165


what’s the difference between Covering Indexes and Clustered Indexes ? how to use clustered index small ?

1975


How can delete duplicate records in cte in sql server?

971


What is update locks?

895


Does a server store data?

931


What is the purpose of object explorer and its features? : sql server management studio

1221