sql server 删除重复

来源:百度知道 编辑:UC知道 时间:2024/06/01 12:21:28
在一个表中,我许多条重复的,如第一条:1. a,b,c,d ;第二条:2 a,b,c,d
.....我现在想把重复的删到只留一条,求大师写一条sql语句.谢谢!!

如果你的id是不重复的话,可以这样写:
delete from [表] where [id列] not in
(
select max([id列]) from [表]
group by [a列],[b列],[c列],[d列]
)

要用三条命令(因为有删除操作,为防止意外,请先备份该表):
select distinct * into #tmp from tablename
truncate table tablename
insert into tablename select * from #tmp