就是有这样一个表
ID   COLL01  COLL02
1    TEST     TEST
2    TEST     TEST
3    TEST1    TEST2
4    TEST     TEST2
5    TEST2    TEST
写一个删除记录,删除除了ID,其他字段都重复的字段,这个该怎么写呢?执行了这个SQL语句后的结果是
ID   COLL01  COLL02
1    TEST     TEST
3    TEST1    TEST2
4    TEST     TEST2
5    TEST2    TEST

解决方案 »

  1.   

    --查詢
    Select * From 表 A Where Exists(Select ID From 表 Where COLL01 = A.COLL01 And COLL02 = A.COLL01 And ID < A.ID)--刪除
    Delete A From 表 A Where Exists(Select ID From 表 Where COLL01 = A.COLL01 And COLL02 = A.COLL01 And ID < A.ID)
      

  2.   

    select distinct * into #Tmp from tableName
    drop table tableName
    select * into tableName from #Tmp
    drop table #Tmp 
      

  3.   

    delete from table1 a,(select MIN(ID),Coll01,Coll02 from table1 group by Coll01,Coll02) b
    where a.coll01 = b.coll01 and a.coll02 = b.coll02 and a.ID<>b.ID
      

  4.   

    JustLovePro(嘉鑫) ( ) 信誉:100  2007-07-19 14:15:42  得分: 0  
     
     
       select distinct * into #Tmp from tableName
    drop table tableName
    select * into tableName from #Tmp
    drop table #Tmp   
     
    ---------------沒看清題意的,這個不是所有列都完全相同的。不需要借助臨時表的。
      

  5.   

    delete from table where ID=(select ID from table where COLL01=(select COLL02 from table))  
      

  6.   

    --上面寫錯了點,修改下
    --查詢
    Select * From 表 A Where Exists(Select ID From 表 Where COLL01 = A.COLL01 And COLL02 = A.COLL02 And ID < A.ID)--刪除
    Delete A From 表 A Where Exists(Select ID From 表 Where COLL01 = A.COLL01 And COLL02 = A.COLL02 And ID < A.ID)
    --再寫一種方法
    --查詢
    Select * From 表 A Where ID Not In(Select Min(ID) From 表 Where COLL01 = A.COLL01 And COLL02 = A.COLL02)--刪除
    Delete A From 表 A Where ID Not In(Select Min(ID) From 表 Where COLL01 = A.COLL01 And COLL02 = A.COLL02)
      

  7.   

    delete from table where ID=(select max(ID) from table where COLL01=(select COLL02 from table))  
      

  8.   

    delete <表名> where ID not in (select MIN(ID) from <表名> group by COLLO1,COLLO2)这是标准答案啦..
      

  9.   

    delete <表名> where ID not in (select MIN(ID) from <表名> group by COLLO1,COLLO2)
    不错。 说不准以后也会用到
      

  10.   

    如果ID是自增列,可以Delete From 表 Where ID Not In(Select Min(ID) From 表 Group By COLL01, COLL02)