|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
delete duplicate items?Does anyone know how to view and delete identical items on table?
What is SQL command to do this. Thanks Here are a couple of resources that may guide you.
http://www.aspfaq.com/2431 http://www.sql-server-performance.com/rd_delete_duplicates.asp -- Show quoteArnie Rowland, Ph.D. Westwood Consulting, Inc Most good judgment comes from experience. Most experience comes from bad judgment. - Anonymous "Qnguyen" <Qngu***@discussions.microsoft.com> wrote in message news:D86F92E6-7057-4FE0-9190-631F76DC896B@microsoft.com... > Does anyone know how to view and delete identical items on table? > What is SQL command to do this. Thanks >> Does anyone know how to view and delete identical items on table? << Why do you have redundant duplicates at all? The PRIMARY KEY shouldhave prevented the problem. If we show you how to clean up your mess, then will you promise to add a real key to the table? Mop the floor then fix the damn leak! Perhaps they are importing data from multiple systems.
Perhaps they are deduplicating address information. sh*t man - you really ought to get out of the class room and get a job and some experience.... -- Show quoteTony Rogerson SQL Server MVP http://sqlblogcasts.com/blogs/tonyrogerson - technical commentary from a SQL Server Consultant http://sqlserverfaq.com - free video tutorials "--CELKO--" <jcelko***@earthlink.net> wrote in message news:1154805763.355731.320590@h48g2000cwc.googlegroups.com... >>> Does anyone know how to view and delete identical items on table? << > > Why do you have redundant duplicates at all? The PRIMARY KEY should > have prevented the problem. > > If we show you how to clean up your mess, then will you promise to add > a real key to the table? Mop the floor then fix the damn leak! > Qnguyen wrote:
> Does anyone know how to view and delete identical items on table? set nocount on> What is SQL command to do this. Thanks declare @id int,@rc int create table #WithDup (id int) insert into #WithDup(id) select id from sysobjects insert into #WithDup(id) select id from sysobjects select top 10 id,count(*) from #withDup group by id having(count(*))>1 order by 2 desc declare cur cursor local static forward_only for select id,count(*)-1 from #WithDup group by id having(count(*))>1 open cur fetch next from cur into @id,@rc while @@fetch_status = 0 begin set rowcount @rc delete #WithDup where id = @id set rowcount 0 fetch next from cur into @id,@rc end deallocate cur select top 100 id,count(*) from #withDup group by id having(count(*))>1 order by 2 desc drop table #withdup Hi There,
You may like to try these methods. 1. Add an idenity Column to the table Allter table yourtable Add myseq int identity(1,1) 2. Delete all the rows where rows are duplicate based on the condition Delete from yourTable where Exists ( Select 1 from YourTable B where Yourtable.column1=B.column1 and Yourtable.column2=B.column2 and Yourtable.myseq <B.myseq ) Or simple 1. Select distinct * into newTable from YourTable 2. delete from Yourtable 3. insert into Yourtable select * from newTable I hope this helps With Warm regards Jatinder Singh http://jatindersingh.blogspot.com http://sqloracle.tripod.com |
|||||||||||||||||||||||