有一张表(T1)规律如下:
COL1   COL2
 1       'A'
 1       'B'
 2       'C'
 2       'C'
 2       'D'
 2       'D'
 3       'E'
 3       'E'
 3       'E'
 .        .
 .        .
 .        .
现在想把表T1中COL1相等、COL2也相等的记录delete了,这样的delete语句怎么写???
删除完后得到的表如下:COL1   COL2
 1       'A'
 1       'B'
 2       'C'
 2       'D'
 3       'E'
 .        .
 .        .
 .        .

解决方案 »

  1.   

    我是新手,没有测过,不要笑我......:delete t1 a where rowid = (
        select max(rowid) from t1 b
         where b.col1 = a.col1
           and b.col2 = a.col2
    )
      

  2.   

    删除表内重复记录的方法 
    可以利用这样的命令来删除表内重复记录: delete from table_name a where rowid< (select max(rowid) from table_name where column1=a.column1 and column2=a.column2 and colum3=a.colum3 and ...)
    不过,当表比较大(例如50万条以上)时,这个方法的效率之差令人无法忍受 
      

  3.   

    delete t1 b where b.col1 in 
     (select * from t1 where t1.col1 != 
      (select max(col1)
       from t1 a  
       where a.col1 = a.col1 and a.col2 = a.col2))
      

  4.   

    我的那个楼主不要用了,今天验证过有问题
    (它没分是不是重复的rows,一律删第一笔)
      

  5.   

    delete t1 b where (b.col1,b.col2) not in 
     (select distinct a.col1,a.col2 from t1 a)
      

  6.   

    都已经在相同的环境下测试过了,我的T1有10万数据,结果如下:rickfeng(VC菜鸟)   提供的方法用时:19分21.4秒,结果不正确;taozhugong()       提供的方法用时:2分42.06秒,结果正确;Eric_1999(Eric)    提供的方法用时:0分31.07秒,结果不正确.再次感谢各位热情解答,taozhugong()获得20分.
      

  7.   

    delete from zzb_userposthis a 
    where rowid != (select max(rowid) from zzb_userposthis 
    where userid=a.userid and postid=a.postid )