记一次mysql去重查询与删除重复记录

查询:

select *,id,count(*) as count from artist group by id having count>1;

删除(删除order_id值大的):

delete from artist where id in( 
SELECT * from 
(select id from artist group by id having count(id) > 1) a)
and order_id not in (
SELECT * from 
(select min(order_id) from artist group by id having count(id )>1) b)

其中:id为重复字段 order_id为自增字段

你可能感兴趣的:(mysql)