用什么SQL语句可以把重复的数据删除?

luzhongjia 2004-04-12 03:21:14
我从别的数据库服务器导入数据,导了几次发现数据重复了,请问用什么SQL语句可以把重复的数据删除?
...全文
35 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
liuhealth 2004-04-12
  • 打赏
  • 举报
回复
刚看到别人(zjcxc)写的,给你参考一下
alter table 你的表 add id int identity(1,1)
go

delete 你的表
from 你的表 a left join(
select id=min(id) from 你的表 group by NUM,BOOKNAME,PRICE
)b on a.id=b.id
where b.id is null
go

alter table 你的表 drop column id
cbzdream 2004-04-12
  • 打赏
  • 举报
回复
几个字段重复?
一个的话用
select distinct * into #t1 from yourtable
truncate table yourtable
insert into yourtable select * from #t1
drop table #t1
多个的话用

select min(field1),min(field2),... into temp1 from Table1 where xxxx group by field1,field2
hlp912 2004-04-12
  • 打赏
  • 举报
回复
用關鍵字﹕distinct
luzhongjia 2004-04-12
  • 打赏
  • 举报
回复
每个记录留一条,别的重复的删除。
Asplin 2004-04-12
  • 打赏
  • 举报
回复
up
zheninchangjiang 2004-04-12
  • 打赏
  • 举报
回复
select distinct * into #t1 from yourtable
truncate table yourtable
insert into yourtable select * from #t1
drop table #t1
jinsfree 2004-04-12
  • 打赏
  • 举报
回复
是全部删掉吗?还是重复的留一条?

ghostzxp 2004-04-12
  • 打赏
  • 举报
回复
你把你 要的 数据 找出来
select distinct 字段名,, into New表 from 表
删掉旧表
holyten 2004-04-12
  • 打赏
  • 举报
回复
用一下Group by
select min(field1),min(field2),... from Table where xxxx group by field1,field2

如果只有一条数据的话,min就是他自己,如果有重复,min也是自己,但是只会出现一次

34,576

社区成员

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

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