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


Please Help Members By Posting Answers For Below Questions

what is the difference between Delete and Truncate command in SQL

706


List out different types of normalizations in sql server and explain each of them?

632


What are the advantages of user defined function?

553


Why would you use sql agent?

806


How check triggers in sql server?

585






Explain what is log shipping?

689


What is xdr?

662


Explain how would you store your query in an SSRS report or a Database server?

94


What is an sql server agent?

627


What are the various editions of sql server 2017 that are available in the market?

571


Does transparent data encryption provide encryption when transmitting data across the network?

714


Which tcp/ip port does sql server run on? How can it be changed?

655


Do you know what are the ways available in sql server to execute sql statements?

625


you accidentally delete the msdb database what effect does this have on your existing sql databases, and how do you recover? : Sql server administration

803


What is faster join or union?

705