delete from table where id not in(select max(id) from table group by name,class)

解决方案 »

  1.   

    select * into #temp from 表 group by 列....
    delete 表
    insert 表 select * from #temp
      

  2.   

    呵呵!看错了! CrazyFor(Fan) 大侠是对的!
    delete from table where id not in(select max(id) from table group by name,class)
      

  3.   

    更正:
    delete from table where id not in(select max(id) from table group by name)
      

  4.   

    TO: pengdali(大力) 
    更正:
    delete from table where id not in(select max(id) from table group by name)你这个语句只要Name相同就认为是重复记录,即不同班级的但人名相同的只会保留一个,显然不符合要求。
      

  5.   

    如果id是唯一标识,不同班级同名不能删的话那么
    delete a from table a,table b where a.id<b.id and a.name=b.name and a.class=b.class