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
Name 3 ways to get an accurate count of the number of records in a table?
What is indexing and its types?
how many bits ip address consist of? : Sql server database administration
Explain different types of index?
How to define and use table alias names in ms sql server?
What are sub reports and how to create them?
What is spid in sql server profiler?
how to overcome kernel isssues
difference between Clustered index and non clustered index ?
How to configure odbc dsn with different port numbers?
What happens if date-only values are provided as date and time literals?
What are the operating modes in which database mirroring runs?
Why we need to use secondry database file? though, we can do same work using primary database file also.
What is the difference between ‘having’ clause and a ‘where’ clause?
Please explain that what are the basic functions for master, msdb, model, tempdb and resource databases? : SQL Server Architecture