Groups | Blog | Home
all groups > sql server mseq > july 2003 >

sql server mseq : Query Question


Brian Scarborough
7/21/2003 12:26:48 PM
I have a table that has a duplicate of each row. I would
like to delete one of the two duplicates out of my table.
I can find the duplicates, but I need the query statement
to delete only one of the two.

thanks

Vishal Parkar
7/22/2003 2:09:11 AM
Refer to his url:
http://support.microsoft.com/default.aspx?scid=KB;en-us;q139444

Method 2:
--using temporary identity column
(if your table does not have a unique column then there is a need to add an
identity column otherwise replace the unique column with the identity column
in the following example)
Ex:
drop table #emp
go
create table #emp(name varchar(300))
go
insert into #emp values ('vishal')
insert into #emp values ('vishal')
insert into #emp values ('vishal1')
insert into #emp values ('vikram')
insert into #emp values ('vijay')
insert into #emp values ('vijay')
insert into #emp values ('vijay')
go
select * from #emp
go
alter table #emp add idd int not null identity(1,1)
go
delete a
from #emp a
where idd not in
(select min(idd) from #emp b where a.name = b.name)
go
select * from #emp
go
alter table #emp drop column idd
go
select * from #emp


--
-Vishal
[quoted text, click to view]

AddThis Social Bookmark Button