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 compound operators?

1040


What is a join in sql? What are the types of joins?

1089


What are the difference between clustered and a non-clustered index?

1033


What does this statement do @@rowcount?

962


How to link tables in sql server?

922


Explain multiserver query

1027


How to read data in a table with "select" statements?

960


What is join query?

878


Can I work with several databases simultaneously? : sql server management studio

979


What is the downside of using udf?

1098


What does select 1 mean?

919


How to provide column names in insert statements in ms sql server?

1144


How much is a sql server license?

945


What is the significance of null value and why should we avoid permitting null values?

978


What is the difference between for trigger and after trigger?

1098