Write a query to delete duplicate records in SQL SERVER
Answer Posted / tallapaneni
create table emp(eid int, ename varchar(50),age int)
insert into emp values( 1,'ramu1,21)
insert into emp values( 1,'ramu2,22)
insert into emp values( 2,'ramu3,22)
insert into emp values( 3,'ramu4,24)
insert into emp values( 4,'ramu5,25)
insert into emp values( 5,'ramu6,26)
insert into emp values( 2,'ramu7,27)
insert into emp values( 6,'ramu8,28)
insert into emp values( 6,'ramu9,29)
SELECT * FROM emp
WITH aaa AS (SELECT (ROW_NUMBER() OVER (PARTITION BY eid
ORDER BY eid)) AS RNum FROM emp)
DELETE FROM aaa WHERE RNum IN (SELECT a.RNum FROM aaa AS a,
aaa AS b WHERE a.RNum > b.RNum GROUP BY a.RNum)
SELECT * FROM emp order by eid
Regards,
Raaam
Is This Answer Correct ? | 3 Yes | 0 No |
Post New Answer View All Answers
What are the recovery models for a database?
What is the stuff and how does it differ from the replace function?
What is the cartesian product of the table?
Can you always create a cache of a report?
How to encrypt data between dialogs?
application server is slow what may be the problem
What are the basic features of a trigger in ms sql server?
What is the maximum size of a dimension? : sql server analysis services, ssas
How can you ensure that the database and sql server based application perform well?
What is tablix?
Is the order of columns in the set clause important in ms sql server?
What is a result set object returned by mssql_query()?
Describe in brief system database.
Name few of the dcl commands in sql?
Is there any difference between primary key and unique with the not null condition?