sql删除表中重复记录

如果一共表中记录重复,删除重复记录,保留一条最新的记录,如下:

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);

发表评论

邮箱地址不会被公开。