MySQL数据去重

倾然丶 夕夏残阳落幕 提交于 2019-11-28 19:20:57

思路

先查询出满足某种条件的数据的最小ID,然后删除最小ID以外的数据就实现了去重

实例

查询最小ID的重复数据

select * from oms_relation_model orm 
where orm.fd_id=
    (
        select min(t.fd_id) from oms_relation_model t 
            where orm.fd_ekp_id=t.fd_ekp_id and orm.fd_ekp_id=t.fd_ekp_id
    )
;

删除操作

delete from oms_relation_model s 
where s.fd_id not in (
    select orm.fd_id from oms_relation_model orm 
    where orm.fd_id=
        (
            select min(t.fd_id) from oms_relation_model t 
            where orm.fd_ekp_id=t.fd_ekp_id and orm.fd_ekp_id=t.fd_ekp_id
        )
);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!