--用临时表做暂存表,如:
select distinct * into #t from tblname
truncate table tblnameInsert into tblname
select * from #tdrop table #t
select distinct * into #t from tblname
truncate table tblnameInsert into tblname
select * from #tdrop table #t
--简单的方法就是借用临时表
--方式:把数据首先放到临时表
--在临时表中处理重复记录问题.
--删除物理数据表
--从临时表把数据取出来,放入物理表中
--删除临时表
Select distinct * into #temp from table1delete table1insert into table1
Select * from #temp drop table #temp方法2:
--方式2:
delete 表名
from 表名 tt
where exists(select 1 from 表名 where 字段=tt.字段 and 字段=tt.字段 and 主键<tt.主键)
方法3
--保留最小的ID
delete 表 where ID not in(select min(ID) from 表 group by 字段...(注:重复的字段行))
http://www.mscenter.edu.cn/laputa/article/2004-12/0/13/10318.xml
楼主的意思是说把所有满足同一条件的记录全部删除吗?
如果是,就如下:
Select * from City where CityName='北京'
楼上WangZWang(阿来) 的意思可能是说,还要保留一条记录、去除与其重复的记录的。
兄弟,做人要厚道!
比如有记录字段code
select code
into #temptable1
from 表
group by code
having count(code)>1select IDENTITY(int,1,1) as '序号' ,表.*
into #temp表
from 表delet from #temp表
where code=#temptable1.重复字段
and
序号 >
( select min(序号) from #temp表
inner join #temptable1 on #temp表.code=#temptable1.code
where #temp表.code=#temptable1.重复字段(从#temptable1取具体的值))
注:这是一条一条删除的
删除原来表中的信息
然后把#temp表信息复制给原来的表
最后drop table #temptable1
drop table #temp表
如果重复的数据量少的话就这么偷懒做吧,呵呵,如果多的话就用游标循环处理