Connecting Tech Pros Worldwide Help | Site Map

Delete Duplicate record from SQL Server2000

  #1  
Old October 4th, 2007, 10:31 AM
Newbie
 
Join Date: Oct 2007
Location: Delhi,India
Posts: 2
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...



  #2  
Old October 10th, 2007, 04:16 PM
jamesd0142's Avatar
Needs Regular Fix
 
Join Date: Sep 2007
Location: Wales
Posts: 469

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
  #3  
Old October 21st, 2007, 08:37 AM
Newbie
 
Join Date: May 2007
Location: Lahore,Pakistan
Posts: 12

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
  #4  
Old December 25th, 2007, 08:34 AM
Newbie
 
Join Date: Dec 2007
Posts: 3

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