9月20号吃鸡比赛:SQL Server数据库中如何识别清除重复数据

来源:百度文库 编辑:高考问答 时间:2024/05/09 06:27:35
我在整理一批公司顾客记录,在记录上顾客姓名字段和电话字段上数据重复很多,在SQL Server数据库中如何通过查询分析两个字段来清除重复数据?

delete top(1) from table where name in( select name from table group by name having count(name)>1 )
通过这个语句
select name from table group by name having count(name)>1
首先查处table表中name字段重复的纪录,
然后删除,
增么删除,具体我还没想到太周全的办法。

select distinct * from 表名

可以使用转换来实现
select distinct * into tableb from tablea
drop table tablea
select * into tablea from tableb
drop table tableb
其中tablea是原表
tableb是转换用的表