sql删除重复记录

mysql 删除重复记录,保留最新的一条:

delete from wechat_exchange_address
    where open_id in (select  open_id from  (select open_id from  wechat_exchange_address  a  group by a.open_id having count(a.open_id) > 1) as a) 
    and id not in (select id from (select max( id) id from wechat_exchange_address group by  open_id having count( open_id)>1) as b);

 

你可能感兴趣的:(mysql)