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
What are the general features of sql server management studio? : sql server management studio
What is apply operator in sql?
Explain what are the restrictions that views have to follow? : SQL Server Architecture
what are user defined datatypes and when you should go for them? : Sql server database administration
What is an indexing strategy?
What are the fixed server level roles? : sql server security
List down some advantages of sql stored procedure?
How to install sql server 2005 express edition?
What is stored procedures?
Which operator do you use to return all of the rows from one query except rows are returned in a second query?
Tell me can we use custom code in ssrs?
Is sql server free?
1.how to find the dead lock in sql server? 2.How to fine the memory leaks in sql server? 3.suppose transaction log file increasing what action will take ?
How many null values we can have in a unique key field in sql server?
What is usually the first word in a sql query?