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

How do indexes help, types?

554


What is the difference between Clustered and Non-Clustered Index?

603


What do you understand by integration services in sql server?

557


What is normalization according to you and explain its different levels?

527


How do you create a data source?

480






How to rename an existing table with the "sp_rename" stored procedure in ms sql server?

543


What is the difference between char, varchar and nvarchar?

581


How to use “drop” keyword in sql server and give an example?

688


What is etl - extraction, transformation, and loading?

525


What is purpose of normalization?

533


Where are sql server user names and passwords stored in sql server?

541


Is null vs coalesce?

510


What is the security principal at the server level that represents your session?

562


What do you understand by triggers and mention the different types of it?

488


How can we improve performance by using SQL Server profiler?

580