读书人

待重复数据筛选

发布时间: 2012-03-01 10:25:47 作者: rapoo

在线等待,重复数据筛选
表1中有个字段 M ,怎样把重复的记录删除啊!

[解决办法]
--假设有唯一字段ID

delete 表名
where id not in (select min(id) from 表名 group by M)

[解决办法]
如果只有一个字段:

select distinct * into #temp from 表

truncate table 表

insert into 表 select * from #temp

drop table #temp

[解决办法]
同意楼上的看法!
如果不只一个字段!

delete a from table a where exists(select 1 from table1 b a.m=b.m and a.id> b.id)

读书人网 >SQL Server

热点推荐