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

Can we use max in where clause?

981


How to write character string constants or literals in ms sql server?

1066


What is not null constraint?

1178


Do you know data definition language, data control language and data manipulation language?

1086


How do I find the query plan in sql server?

1015


Explain raiserror in sql server?

1075


Why do we use sql limitations? Which constraints can we use while making a database in sql?

1123


What is buffer cash in sql server?

1203


What is the use of @@spid?

1047


What is Fragmentation and Defragmentation? For 32GB Table,How can we do the fragmentation?

4453


What do you understand by replication in sql server?

1124


my name is sejal I have cleared the sbi clerk exam. I am BCA graduate My favorite subject RDBMS Relational database management system. so please send me rRDBMS related interview questions

1982


Explain different forms of normalization?

1001


What are different types of statements that are supported by sql?

1097


What is sql injection? How to protect against sql injection attack?

1035