delete from tablename where a not int (select top 1 a from tablename )
delete from tablename where a not in (select top 1 a from tablename )
select top 1 * into #temp from A delete from A insert into A select * from #temp drop table #temp或则DELETE A FROM (SELECT TOP 1 * FROM A) AS t WHERE A.id <> t.id
create table a( A int) insert into a select 123 insert into a select 324 insert into a select 563 go delete from a where a not in (select top 1 a from a order by a ) 楼主真客气,没有分,没有关系,重要的是大家来论坛交流 记住千万别倒分,刚才,看见了一个,不太高兴
用一個臨時表來處理 select identity(int,1,1) as nowid,主书目ID,其余字段1,其余字段2,其余字段3,…… into #temp1 from YourTabledelete YourTableinsert into YourTable select 主书目ID,其余字段1,其余字段2,其余字段3,…… from #temp1 where nowid in (select min(nowid) from #temp1 group by 主书目ID)drop table #temp1select * from YourTable
delete from A
insert into A select * from #temp
drop table #temp或则DELETE A
FROM (SELECT TOP 1 * FROM A) AS t
WHERE A.id <> t.id
insert into a select 123
insert into a select 324
insert into a select 563
go
delete from a
where a not in (select top 1 a from a order by a )
楼主真客气,没有分,没有关系,重要的是大家来论坛交流
记住千万别倒分,刚才,看见了一个,不太高兴
其中一个字段是:主书目ID
在这个字段下有好多记录。比如
2
2
36
3
3
89
6
6等。
我是想留下
2
36
3
89
6
删掉重复的记录中,除第一下之外的所有的。
保证在此字段下没有重复的。
select identity(int,1,1) as nowid,主书目ID,其余字段1,其余字段2,其余字段3,…… into #temp1 from YourTabledelete YourTableinsert into YourTable select 主书目ID,其余字段1,其余字段2,其余字段3,…… from #temp1 where nowid in (select min(nowid) from #temp1 group by 主书目ID)drop table #temp1select * from YourTable