How to delete the duplicate rows from a table in SQL Server ??

Answer Posted / vnreddy

create table sampletbl(id int,name varchar(100))

insert into sampletbl values(1,'aa')
insert into sampletbl values(1,'aa')
insert into sampletbl values(1,'aa')
insert into sampletbl values(2,'bb')
insert into sampletbl values(2,'bb')

with cte as(
select ROW_NUMBER() over (partition by id order by id) as r_no,* from sampletbl)
delete from cte where r_no>1

select * from sampletbl

Is This Answer Correct ?    10 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain different types of self contained sub query?

538


What are the steps to follow to configure SQL*Net?

557


Do you think BCNF is better than 2NF & 3NF? Why?

778


Tell me about the approaches which you used to counter the DI problems.

751


Tell me what are cursors and when they are useful?

506






Is BCNF better than 2NF & 3NF? Why?

616


How to execute a sql statement using mssql_query()?

541


What is a partition key?

519


How to use subqueries with the exists operators in ms sql server?

581


What is sql injection? How to protect against sql injection attack?

551


What is best institute to Learn DotNET And SQL in chennai?

1686


What is named calculation? : sql server analysis services, ssas

527


What do you mean by collation recursive stored procedure?

585


Can two tables have the same primary key?

559


What are different type of Collation Sensitivity?

552