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 retrieve duplicate rows in a table?
How to delete the duplicate entries in a table?

Answer Posted / sameer

--select * from #TempR
select * into #temp2 from #TempR

-- select * from #temp2

alter table #temp2 add record_id numeric(5,0) identity not
null

/* select those row which are repeated */

select * into #qwe
from #temp2
where exists(

select null from #temp2 b
where b.ID = #temp2.ID
and b.TYPE = #temp2.TYPE
group by b.ID, b.TYPE
having
count (*) >=2
)

--select * from #qwe




/* delete those row which are repeted */

delete from #TempR where ID in ( select ID from #qwe)

/* insert those row which are deleted */

delete from #qwe where record_id not in (

select record_id
from #qwe
group by ID, TYPE
having record_id = max (record_id)
)

-- select * from #qwe
alter table #qwe drop record_id

insert into #TempR
select * from #qwe

/* see output */


select * from #TempR

/* check for row getting repeted */


select *
from #TempR
where exists(

select null from #TempR b
where b.ID = #TempR.ID
and b.TYPE = #TempR.TYPE
group by b.TT_ID, b.EQP_TYPE
having
count (*) >=2
)

Is This Answer Correct ?    1 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is indexing in sql server with example?

935


What is full outer join in sql server joins?

997


What is global temp table?

960


Explain security with sql azure?

186


What stored by the master?

915


How to throw custom exception in Stored Procedure?

1006


Explain isolation levels that sql server supports?

998


List out the differences between the clustered index and non-clustered index in sql server?

953


What is log shipping?

917


What is data modeling and Reterminal integrity?

1919


what is the difference between a primary key and a unique key? : Sql server database administration

960


Do you know what is bit data type and whats the information that can be stored inside a bit column?

919


You notice that the transaction log on one of your databases is over 4gb the size of the data file is 2mb what could cause this situation, and how can you fix it?

1086


how to restart sql server in single user mode? How to start sql server in minimal configuration mode? : Sql server database administration

859


Which table keeps information about stored procedures?

898