Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

what is the system function to get current user's user id? : Sql server database administration

1005


What is multilevel indexing?

929


What are three major types of constraints?

1120


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

1042


Differentiate between a having clause and a where clause.

965


How do you send email on SQL Server?

1066


What are orphan records?

932


What is the difference between NOROW and LOCKROW?

2840


Explain indexed views?

986


Explain the categories of stored procedure?

937


What is a transact-sql statement?

1065


what is a schema in sql server 2005? : Sql server database administration

1032


After removing a table from database, what other related objects have to be dropped explicitly?

1056


Can we perform backup restore operation on tempdb?

1017


What happens if we shrink log file in sql server?

983