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 is the system function to get current user's user id? : Sql server database administration
What is multilevel indexing?
What are three major types of constraints?
It is important form e to get the information from log files of applications executed by the task scheduler? Does sql studio save these log files? : sql server management studio
Differentiate between a having clause and a where clause.
How do you send email on SQL Server?
What are orphan records?
What is the difference between NOROW and LOCKROW?
Explain indexed views?
Explain the categories of stored procedure?
What is a transact-sql statement?
what is a schema in sql server 2005? : Sql server database administration
After removing a table from database, what other related objects have to be dropped explicitly?
Can we perform backup restore operation on tempdb?
What happens if we shrink log file in sql server?