Connecting Tech Pros Worldwide Forums | Help | Site Map

Delete Duplicate record from SQL Server2000

Newbie
 
Join Date: Oct 2007
Location: Delhi,India
Posts: 2
#1   Oct 4 '07
Hi friends,

Step1-
create table duplicate
(
intId int, varName varchar(50)
)
insert into duplicate(intId,varName) values(1,'rajesh')
insert into duplicate(intId,varName) values(2,'raj12')
insert into duplicate(intId,varName) values(1,'rajesh')
insert into duplicate(intId,varName) values(2,'raj12')
insert into duplicate(intId,varName) values(3,'raj12')

Step2-
---Create Duplicate table
create table #dupTbl
(
intId int, varName varchar(50)
)
insert into #dupTbl
select intId,varName from duplicate group by intId,varName having count(*) > 1

Step3-

delete from duplicate where intId in (select intId from #dupTbl)

Step4-

insert into duplicate
select intId,varName from #dupTbl

Finished...............
You can checked your table...



jamesd0142's Avatar
Needs Regular Fix
 
Join Date: Sep 2007
Location: Wales
Posts: 467
#2   Oct 10 '07

re: Delete Duplicate record from SQL Server2000


Additionally look at this post... i believe its a simpler way and works well for me!

http://www.thescripts.com/forum/thread721118.html
Newbie
 
Join Date: May 2007
Location: Lahore,Pakistan
Posts: 12
#3   Oct 21 '07

re: Delete Duplicate record from SQL Server2000


hi,

The above link has a good way to accoplish the task but here is another possibility but would work if there is some id column;

Delete all duplicate records ..
select distinct will bring all the uniquie records and rest would the duplicate and will be deleted.

Expand|Select|Wrap|Line Numbers
  1. Delete * from YourTable where ID <> IN ( SELECT Distinct IDColumn from YourTable)
Thanks,
Munawar
Newbie
 
Join Date: Dec 2007
Posts: 3
#4   Dec 25 '07

re: Delete Duplicate record from SQL Server2000


Following website demonstrates easiest way to delete duplicate records from SQL Server (any version).

http://blog.sqlauthority.com/2007/03...-records-rows/

Regards,
Reply