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 / meher
1. To get the duplicate records.
Use group by clause to the column on which you want to
check the duplicates records.
syntax:
select column_name, count(*) from table_name group by
column_name having count(*) >1
2. To delete the duplicate records.
syntax:
delete from table_name where rowid in (select max(rowid)
from table_name group by column_name having count(*)>1 )
This will work.
Please let me know in case of any issues.
| Is This Answer Correct ? | 2 Yes | 2 No |
Post New Answer View All Answers
Does partitioning improve performance?
Mention the 3 ways to get a count of the number of records in a table.
Difference between Inner vs outer joins?
Can you force a query to use a specific index?
Once setting replication, can you have distributor on sql server 2005, publisher of sql server 2008?
What is policy based management (pbm)? : sql server database administration
How you provide security to cube? : sql server analysis services, ssas
Mention what are the core components of ssrs?
Is null vs coalesce?
Explain the difference between delete,drop and truncate in SQL Server?
How to view the error log for any specific instance? : sql server database administration
What is the bookmark lookup and rid lookup?
How to create a view using data from another view?
What are the common performance issues in sql server?
How self join is different from outer join?