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 the order in which the sql query is executed?

527


How to create a store procedure with encryption?

527


What are the advantages of paper records?

559


What are system databases into sql server (2005/2008)?

591


What are different types of table joins?

562






How can you list all the table constraints in a database?

518


How can I change procedure name in sql server?

541


Explain the difference between delete,drop and truncate in SQL Server?

592


How adventureworkslt tables are related?

533


How will you hide an attribute? : sql server analysis services, ssas

527


What is difference between order by and group by?

578


What command would you use to add a column to a table in sql server?

754


What are differences in between sql server 2012 and sql server 2016?

576


What is difference between views and tables?

471


What are the disadvantages of using querystrings to send data from one page to another?

588