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 / guest

WITH T1 AS (
SELECT ROW_NUMBER () OVER ( PARTITION BY EmpId ORDER BY
EmpId) AS RNUM,EmpId FROM EMP)
delete
FROM T1 WHERE RNUM > 1

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is NOT NULL Constraint in sql server 2012?

599


Explain a checkpoint?

532


How do triggers work?

536


What is role playing dimension with two examples? : sql server analysis services, ssas

584


What is the use of stored procedure?

512






How to create a view using data from another view?

563


What are “phantom rows”?

1240


How to rebuild master databse?

661


What is the new security features added in sql server 2014? : sql server security

563


What is the difference between sdf and mdf?

677


Explain primary key, foreign key and unique key?

536


Which tcp/ip port does the sql server run on? How can it be changed?

523


Explain about temporary stored procedure?

522


Explain about SQLOS?

584


How can I know what locks are running on which resource?

502