mysql刪除重復數據分為兩種情況: 一、以一個字段來唯一確定一條記錄,可以用以下SQL來刪除: delete glt_entity_tmp from glt_entity_tmp,(select idd from glt_entity_tmp group by nam having count(*) > 1 ) as t2 where glt_entity_tmp.idd=t2.idd
注意:數據中idd不一致,其它字段信息都一致,如果是一個nam有多于2條重復的記錄,要執行多次
二、以二個或以上字段來唯一確定一條記錄,可以用以下SQL來刪除,但要注意每條記錄中必須有第三個字段來唯一確定這條記錄(使用max刪除) delete gbi_pd_theme_new_tmp from gbi_pd_theme_new_tmp,(select new_code,the_code,max(the_new_code) as the_new_code from gbi_pd_theme_new_tmp group by new_code,the_code having count(*) > 1) as t2 where gbi_pd_theme_new_tmp.new_code=t2.new_code and gbi_pd_theme_new_tmp.the_code=t2.the_code and gbi_pd_theme_new_tmp.the_new_code=t2.the_new_code