create table marxBrothers (
Number int,
Name varchar(32)
)
go
insert marxBrothers
select 1, 'Groucho Marx' UNION ALL
select 2, 'Harpo Marx' UNION ALL
select 3, 'Chico Marx' UNION ALL
select 1, 'Groucho Marx' UNION ALL
select 2, 'Harpo Marx' UNION ALL
select 3, 'Chico Marx' UNION ALL
select 6, 'Zeppo Marx' UNION ALL
select 7, 'Gummo Marx' UNION ALL
select 6, 'Zeppo Marx'
begin tran deduplicate
select DISTINCT *
into #temp
from marxBrothers
truncate table marxBrothers
insert marxBrothers
select *
from #temp
select * from marxBrothers
drop table #temp
commit tran deduplicate
drop table marxBrothers
create table marxBrothers (
ident int IDENTITY,
Name varchar(32)
)
go
insert marxBrothers (Name)
select 'Groucho Marx' UNION ALL
select 'Harpo Marx' UNION ALL
select 'Chico Marx' UNION ALL
select 'Groucho Marx' UNION ALL
select 'Harpo Marx' UNION ALL
select 'Chico Marx' UNION ALL
select 'Zeppo Marx' UNION ALL
select 'Gummo Marx' UNION ALL
select 'Zeppo Marx'
select * from marxBrothers
delete marxBrothers
from marxBrothers,
(
select min(ident) as minIdent, name
from marxBrothers m
group by name
having count(1) > 1
) as derived
where marxBrothers.name = derived.name
and ident > minIdent
select * from marxBrothers
drop table marxBrothers