if object_id('a') is not null drop table a go create table a(id int identity(1,1), date datetime) go insert into a values('2015-02-04') insert into a values('2015-02-05') insert into a values('2015-02-05') insert into a values('2015-02-05') insert into a values('2015-02-06') insert into a values('2015-02-06')go delete from a where id not in (select MIN(id) as id from a group by date) go select * from a
go
create table a(id int identity(1,1),
date datetime)
go
insert into a values('2015-02-04')
insert into a values('2015-02-05')
insert into a values('2015-02-05')
insert into a values('2015-02-05')
insert into a values('2015-02-06')
insert into a values('2015-02-06')go
delete from a where id not in (select MIN(id) as id from a group by date)
go
select * from a
select * from a
select * from b