RT 表中ID 唯一, name存在重复  如何删除name重复的记录  保留一条数据

解决方案 »

  1.   

    \
    delete from tt a where not exists(select 1 from tt where a.name=name and a.id>id)
      

  2.   

    or
    delete tt from tt inner join (select name,min(id) as mi from tt) b
    on tt.name=b.tt and tt.id>b.mi
      

  3.   

    delete a from table1 a left join (select min(id) from table1 group by name) b on a.id=b.id
      

  4.   

    or
    delete tt from tt inner join (select name,min(id) as mi from tt group by name) b
    on tt.name=b.name and tt.id>b.mi
      

  5.   

    需要加上条件。 where b.id is null
    delete a from table1 a left join (select min(id) from table1 group by name) b on a.id=b.id where b.id is null
      

  6.   

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

  7.   

    create temporary table asd1
    select id from t a where exists(select 1 from t where a.name=name and a.id >id)delete  t from t,asd1
    where t.id =asd1.id