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

Explain the purpose of indexes?

544


what are the different types of replication you can set up in sql server? : Sql server database administration

514


Explain the database you used in your final year project?

536


How can windows applications connect to sql servers via odbc?

582


What is the New in SQL server 2008?

577






Can you tell me some of the common replication dmv's and their use? : sql server replication

536


What are different types of roles provided by ssrs?

112


How to truncate the log in sql server 2012? : sql server database administration

573


Why is sql server log file full?

536


What does the on delete cascade option do?

550


explain different levels of normalization? : Sql server database administration

522


What do you mean by normalisation?

498


Where to find ntwdblib.dll version 2000.80.194.0?

554


Where are full-text indexes stored?

573


What is the use of RDBMS?

591