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
Can we use max in where clause?
How to write character string constants or literals in ms sql server?
What is not null constraint?
Do you know data definition language, data control language and data manipulation language?
How do I find the query plan in sql server?
Explain raiserror in sql server?
Why do we use sql limitations? Which constraints can we use while making a database in sql?
What is buffer cash in sql server?
What is the use of @@spid?
What is Fragmentation and Defragmentation? For 32GB Table,How can we do the fragmentation?
What do you understand by replication in sql server?
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
Explain different forms of normalization?
What are different types of statements that are supported by sql?
What is sql injection? How to protect against sql injection attack?