if 3 duplicate records in table,i want to delete 2 alternating
duplicate records by keeping 1 duplicate and 1 original as it
is,how?

Answer Posted / sivam

sno sname salary
1 aaa 1000
1 aaa 1000
2 bbb 2000
2 bbb 2000
2 bbb 2000
1 aaa 1000

;with aa as
(
select sname,salary,ROW_NUMBER()over(partition by sno,sname,salary order by sno,sname,salary) as Nos from #testtable
)

delete from aa where Nos%2<>0

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why are views required in the sql server or in any other database?

530


Do you know how to store and query spatial data?

596


Define self join in sql server joins?

514


what is the difference between Tabular and Matrix report?

122


Explain log shipping and mention its advantages.

587






What are ddl (data definition language) statements for tables in ms sql server?

534


What is the contrast between sql and pl/sql?

617


How to loop through the result set with @@fetch_status?

654


What is difference between materialized view and view?

476


Which trace flags are enabled in sql server?

520


What are the results of running this script?

505


What is sql server database?

492


Other than truncate statement, which other command can by-pass the trigger on the tables?

612


How do I find information about the install locations for the various instances running on a computer?

545


What are trace flags?

586