删除重复记录!

swand 2003-05-10 03:23:25
表中上万的重复记录用什么语句一次性删除?
...全文
26 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
mahatma_cn 2003-05-18
  • 打赏
  • 举报
回复
严重关注!
iamtotoo 2003-05-12
  • 打赏
  • 举报
回复
e
evilks 2003-05-11
  • 打赏
  • 举报
回复
monkey哥,我试了你写的代码,报错说列名id无效,是什么意思?
iainet 2003-05-10
  • 打赏
  • 举报
回复
不好意思,刚才看错了,但一这样一来就全删除了,怎么才能够留下一条啊?
我想想吧,想好再说?
iainet 2003-05-10
  • 打赏
  • 举报
回复
发上代码有点疑问,如果数据有3行完全相同呢?
能否实现!好像不行吧,我看只能够对有2行相同的起作用!
我实验一下再说!
caiyunxia 2003-05-10
  • 打赏
  • 举报
回复
可以呀
GROUP BY 选择重复列 不能包括ID
psxfghost 2003-05-10
  • 打赏
  • 举报
回复
Monkey兄,这样好像也不能删除重复的数据,都要留一条,不知这样如何:

alert table [表名] add id int identity(1,1)

select count(id) as num,列名 into #temp from 表名 group by 列名
delete from table where 列名 in(select 列名 from #temp where num>1)
drop table #temp

alert table [表名] drop column id
caiyunxia 2003-05-10
  • 打赏
  • 举报
回复
alert table [表名] add id int identity(1,1)

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

alert table [表名] drop column id
psxfghost 2003-05-10
  • 打赏
  • 举报
回复
其中,distinct把重复记录全部压缩为一条记录!
psxfghost 2003-05-10
  • 打赏
  • 举报
回复
select distinct * into #temp from table
delete from table
insert into table select * from #temp
drop table #temp

34,576

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧