用户名: 密码: 验证码: 注册           网站地图 高级搜索 RSS订阅 收藏本站
山东十七地市站长联盟信息: 济南 青岛 淄博 枣庄 东营 烟台 潍坊 济宁 泰安 威海 日照 莱芜 临沂 德州 聊城 滨州 菏泽      
您的位置:主页>网络编程>Mssql>

怎样保留重复记录中的第一条记录

[ 来源: | 作者: | 更新日期:2007-11-30 16:05:35 | 评论 0 条 | 我要投稿 ]

有一个表里面有某个字段出现重复记录,怎样保留重复记录中的第一条记录 字串5

select   *,identity(int,1,1)   ID   into   #t1   from   table1  
  delete   a  
  from   #t1   a  
  where   ID   >   (select   min(ID)   from   #t1   where   field1=a.field1   and  
    field2=a.field2   and   ...   fieldn=a.fieldn)  
   
  trancate   table   table1  
  alter   table   #t1   drop   column   ID  
  insert   into   table1   select   *   from   #t1

字串7


也许可以这样,简便些  
  select   distinct   *   into   #t1   from   table1  
  trancate   table   table1  
  insert   into   table1   select   *   from   #t1 字串9


Tags:记录 第一 重复 保留 怎样 #t1 from table1 select into
您的评论
用户名:新注册) 密码: 匿名评论 [所有评论]

·用户发表意见仅代表其个人意见,并且承担一切因发表内容引起的纠纷和责任
·本站管理人员有权在不通知用户的情况下删除不符合规定的评论信息或留做证据
·请客观的评价您所看到的资讯,提倡就事论事,杜绝漫骂和人身攻击等不文明行为