Sunday, 18 February 2018

Write sql query to delete repeated record

create table #temp
(
 id int,
 name varchar(100)
)

insert into #temp(id,name) values(1,'A'),(2,'A'),(3,'B'),(4,'C'),(5,'A'),(6,'B'),(7,'D'),(8,'E'),(9,'A')


delete from #temp where id not in (select max(t.id) from #temp t group by t.name having count(t.id) >= 1 )

No comments:

Post a Comment