By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,688 Members | 1,226 Online
Bytes IT Community
Submit an Article
Got Smarts?
Share your bits of IT knowledge by writing an article on Bytes.

Delete Duplicate record from SQL Server2000

P: 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...
Oct 4 '07 #1
Share this Article
Share on Google+
3 Comments


jamesd0142
100+
P: 469
Additionally look at this post... i believe its a simpler way and works well for me!

http://www.thescripts.com/forum/thread721118.html
Oct 10 '07 #2

P: 12
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
Oct 21 '07 #3

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

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

Regards,
Dec 25 '07 #4