找出重複行並進行刪除

##找出重複行
create table t1 as (select t.tname,t.tname2, count(*) cnt from  test1 t   group by t.`tname`,t.`tname2` having cnt>1 order by  t.tname ,t.tname2);

 


##從t1中選出id最大的那一行

create table t2 as (select max(t1.tid) maxid,t1.tname,t1.tname2 from t1 );

 

##刪除重複行

delete from test1 t where t.tid !=(select maxid from t2 where t.tname=t2.tname and t.tname2=t2.tname2);

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章