if 3 duplicate records in a table,i want to delete 2 duplicate
records by keeping 1 duplicate and 1 original as it is,how?
Answer Posted / mohamed zunu
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')
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 ? | 9 Yes | 1 No |
Post New Answer View All Answers
Why we use functions in sql server?
How to check what was the last restore transaction LSN in Log shipping or Mirroring? when we don't have a Monitor or witness server.
difference between Clustered index and non clustered index ?
How to modify the underlying query of an existing view?
Do you know the policy based administration feature of sql server 2008?
What is history table in sql server?
How do I clean up sql server transaction log?
How to replace null values in expressions using isnull()?
Why do we use trigger?
What are statistics?
What are the restrictions while creating batches in sql server?
How to recover from sql injection? : sql server security
What is model database in sql server?
why does a sql statement work correctly outside of a user-defined function, but incorrectly inside it? : Sql server administration
What is the difference between left and right outer join?