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
how would you troubleshoot blocking? : Sql server database administration
What happens if we shrink log file in sql server?
Suppose you want to implement the following relationships while designing tables. How would you do it?a.) One-to-oneb.) One-to-manyc.) Many-to-many
Explain few examples of stored procedure over triggers?
How optimize sql query with multiple joins in sql server?
What is table value parameters (tvp)?
Define full outer join?
What happens when converting big values to integers?
What is the purpose of sql profiler in sql server? : sql server database administration
Where are sql server user names and passwords stored in sql server?
How to create an index on an existing table in ms sql server?
What is thr feature of change data capture?
Do you know the cursor types?
What is equi join with example?
Write an SQL query to obtain the 2nd highest salary.