您好,欢迎来到思海网络,我们将竭诚为您提供优质的服务! 诚征网络推广 | 网站备案 | 帮助中心 | 软件下载 | 购买流程 | 付款方式 | 联系我们 [ 会员登录/注册 ]
促销推广
客服中心
业务咨询
有事点击这里…  531199185
有事点击这里…  61352289
点击这里给我发消息  81721488
有事点击这里…  376585780
有事点击这里…  872642803
有事点击这里…  459248018
有事点击这里…  61352288
有事点击这里…  380791050
技术支持
有事点击这里…  714236853
有事点击这里…  719304487
有事点击这里…  1208894568
有事点击这里…  61352289
在线客服
有事点击这里…  531199185
有事点击这里…  61352288
有事点击这里…  983054746
有事点击这里…  893984210
当前位置:首页 >> 技术文章 >> 文章浏览
技术文章

六种SQL Server数据库删除数据库重复行实用方法

添加时间:2012-6-5  添加: admin 

SQL Server删除重复行是我们最常见的操作之一,下面就为您介绍六种适合不同情况的SQL Server删除重复行的方法,供您参考。

1.如果有ID字段,就是具有唯一性的字段

delect   table   where   id   not   in   (        select   max(id)   from   table   group   by   col1,col2,col3...      )      group by 子句后跟的字段就是你用来判断重复的条件,如只有col1,那么只要col1字段内容相同即表示记录相同。

2. 如果是判断所有字段也可以这样

select   *   into   #aa   from   table   group   by   id1,id2,....      delete   table        insert   into   table        select   *   from   #aa  3. 没有ID的情况

select   identity(int,1,1)   as   id,*   into   #temp   from   tabel      delect   #   where   id   not   in   (      select   max(id)   from   #   group   by   col1,col2,col3...)      delect   table      inset   into   table(...)      select   .....   from   #temp  4. col1+','+col2+','...col5 联合主键

select   *   from     table   where   col1+','+col2+','...col5   in   (      select   max(col1+','+col2+','...col5)   from   table        where   having   count(*)>1      group   by   col1,col2,col3,col4        )   group by 子句后跟的字段就是你用来判断重复的条件,如只有col1,那么只要col1字段内容相同即表示记录相同。

5.

select   identity(int,1,1)   as   id,*   into   #temp   from   tabel      select   *   from     #temp   where   id   in   (      select   max(id)   from   #emp   where   having   count(*)>1   group   by   col1,col2,col3...)     6.

select   distinct   *   into   #temp   from   tablename        delete   tablename        go      insert   tablename   select   *   from   #temp   Sqlclub    go      drop   table   #temp 

关键字:SQL Server、删除、重复行

分享到:

顶部 】 【 关闭
版权所有:佛山思海电脑网络有限公司 ©1998-2024 All Rights Reserved.
联系电话:(0757)22630313、22633833
中华人民共和国增值电信业务经营许可证: 粤B1.B2-20030321 备案号:粤B2-20030321-1
网站公安备案编号:44060602000007 交互式栏目专项备案编号:200303DD003  
察察 工商 网安 举报有奖  警警  手机打开网站