表Information中有四个字段:ID,Name,Sex,Position

上一篇 / 下一篇  2007-05-29 22:16:51 / 个人分类:DataBase

delete   from   information   t0  
  where   exist   (select   id    
                            from   information   t1    
                            where   t1.id<t0.id   and   t1.name=t0.name)

 

 

你不是说ID是主键吗,既然是主键,就不应该有两条完全相同的记录。  
  我的语句你说有错,用飘香兄改过的,以下语句查出Name有重复的记录,删除Name相同而ID不是最大的记录,也就是保留ID最大的一条记录,其他的删除。  
  delete   a                                              
  from   Information   a,  
  (  
  select   max(id)   as   id,Name   from   Information    
  group   by   name   having   count(*)>1  
  )   as   b  
  where   a.id<>b.id  
  and   a.name=b.name  


TAG: DataBase

 

评分:0

我来说两句

日历

« 2024-04-11  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 13599
  • 日志数: 23
  • 建立时间: 2007-05-12
  • 更新时间: 2007-06-18

RSS订阅

Open Toolbar