记一次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为自增字段

猜你喜欢

转载自blog.csdn.net/qq_18881987/article/details/82118587
今日推荐