I have a table EMP in which the values will be like this

EmpId Ename Sal DeptId
11 Ram 10000 10
11 Ram 10000 10
22 Raj 20000 20
22 Raj 20000 20
33 Anil 15000 30
33 Anil 15000 30

I want to delete only duplicate Rows. After Delete I want
the output like this

EmpId Ename Sal DeptId
11 Ram 10000 10
22 Raj 20000 20
33 Anil 15000 30



Answer Posted / smitha

;with empctc(empid,ename,sal,deptid,ranking)
as
(Select empid,ename,sal,deptid,ranking=Dense_rank() over (
partition by empid,ename,sal,deptid order by NEWID() asc)
from emp
)
delete * from empctc where ranking>1

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the benefits and tasks of object explorer? : sql server management studio

792


What are the limitations in ssrs on sql server express edition?

158


what are the steps you will take, if you are tasked with securing an sql server? : Sql server database administration

729


What is normalization and what are the advantages of it?

697


What are page splits? : SQL Server Architecture

737






What are the instances when triggers are appropriate?

711


Tell me about pre-defined functions of sql?

854


What are the types of indexing?

817


What is sqlservr.exe - process - sql server (sqlex?press)?

784


How to attach adventureworkslt physical files to the server?

812


What is filestream?

736


Explain the database you used in your final year project?

710


What is oltp (online transaction processing)?

740


how to overcome kernel isssues

1348


What do you mean by an execution plan? Why is it used?

724