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...


How to delete the duplicate rows from a table in SQL Server ??

Answers were Sorted based on User's Feedback



How to delete the duplicate rows from a table in SQL Server ??..

Answer / vnreddy

create table sampletbl(id int,name varchar(100))

insert into sampletbl values(1,'aa')
insert into sampletbl values(1,'aa')
insert into sampletbl values(1,'aa')
insert into sampletbl values(2,'bb')
insert into sampletbl values(2,'bb')

with cte as(
select ROW_NUMBER() over (partition by id order by id) as r_no,* from sampletbl)
delete from cte where r_no>1

select * from sampletbl

Is This Answer Correct ?    10 Yes 2 No

How to delete the duplicate rows from a table in SQL Server ??..

Answer / sudha511

select distinct * into #temp from sampletbl
delete sampletbl
insert into sampletbl
select * from #temp
drop table #temp

Is This Answer Correct ?    2 Yes 0 No

How to delete the duplicate rows from a table in SQL Server ??..

Answer / himmat

delete from table name
having count(column name)>1
group by column name

Is This Answer Correct ?    15 Yes 25 No

Post New Answer

More SQL Server Interview Questions

what are user defined datatypes? : Sql server database administration

0 Answers  


in tabase table having a column in it empname field is there which having 5 duplicate values is there i want deleted all the duplicates i want showing only one name only.

7 Answers  


Tell me about normalization in DBMS.

0 Answers   Honeywell, Zomato,


Is it possible to allow NULL values in foreign key? I s it possible to use different constraints for the same column in the table (i.e) (id int NOT NULL,UNIQUEUE)

1 Answers  


Is foreign key unique?

0 Answers  


What is nolock?

0 Answers  


Determine when to use stored procedure to complete sql server tasks?

0 Answers  


How to create stored procedures with parameters in ms sql server?

0 Answers  


How important do you consider cursors or while loops for a transactional database?

0 Answers  


Write the queries for commands like Create Table, Delete table, Drop Table etc.

0 Answers   HPCL, Hughes Systique Corporation,


In which files does sql server actually store data?

0 Answers  


Explain Trigger with an example?

2 Answers  


Categories