有这么一张表,
有三个列
id       name    pd
1        eoeoe    23l342o23
2        eoeoem   232
3        2        1
4        2        2
5        3        1
6        3        1
7        2        2
ID是自动编号的
现在要把这个表保持ID最小,也就是把name和pd相同的删除。
让表的ID号最少.

解决方案 »

  1.   

    delete from table1 A where exists (select * from table1 B where A.ID>B.ID and A.name=B.name and A.pd=B.pd)
      

  2.   

    LZ,怎么表达的意思这么难理解
    是要ID号最小的一条记录,把其余的删掉
    还是删掉后两个字段值相等的记录,使得ID数目最少
      

  3.   

    delete A from table1 A where not exists (select * from table1 B where A.name=B.name and A.pd=B.pd and B.ID<a.ID)
      

  4.   

    --ordelete from tablename where id not in (select min(id) from tablename group by name,pd)