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 store procedure?

819


When would you prefer to have a minimum number of indexes?

657


What is the difference between a stored procedure and a user defined function?

743


Why we use functions in sql server?

715


What command is used to rename the database?

682






Explain the different types of joins?

743


Can we run Reporting Services with SQL Server express edition, which is a free version of SQL Server?

96


how many clustered indexes can be created on a table? : Sql server database administration

774


Explain Geography datatype in SQL Server

805


What do you understand by coalesce in sql server?

722


What are the steps to take to improve performance of a poor performing query? : sql server database administration

784


How to write the storeprocedure with in the store procedure? and how can we write the store procedure with in a trigger vice versa? plz post me the exact answer?

2333


what are the types of indexes? : Sql server database administration

793


How to trouble shoot if unable to connect SQL Server

1677


What is 2nf normalization?

732