UPDATE pd_user set id_card=REPLACE(id_card,' ',''); INSERT INTO pd_temp_idcard SELECT MIN(uid) AS minUid, id_card FROM pd_user WHERE LENGTH(id_card) > 0 GROUP BY id_card HAVING COUNT(*) > 1; DELETE b.* from pd_temp_idcard a, pd_user b where a.id_card=b.id_card and a.minUid != b.uid and LENGTH(b.id_card)>0 ; UPDATE pd_user SET id_card=null where LENGTH(id_card)=0