Home  >  Article  >  Database  >  删除SQL Server数据中指定的重复记录

删除SQL Server数据中指定的重复记录

WBOY
WBOYOriginal
2016-06-07 16:22:201081browse

delete from 表 where 主键=(select top 1 主键 from 表 where 相同字段=(select 相同字段 from 表 group by 相同字段 having count(*)1)) 主键是表中绝对没有重复值的字段,如自动增量ID; 相同字段如采集时间,删除表中采集时间相同的记录 本语句,每执行一

   delete from 表 where 主键=(select top 1 主键 from 表 where 相同字段=(select 相同字段 from 表 group by 相同字段 having count(*)>1))

  主键是表中绝对没有重复值的字段,如自动增量ID;

  相同字段如“采集时间”,删除表中采集时间相同的记录

  本语句,每执行一次,只能删除一条重复记录,如果有三条记录有相同“采集时间”,,就要循环执行该语句两次。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn