码迷,mamicode.com
首页 > 数据库 > 详细

mysql 删除某字段重复数据并保留id最小的数据

时间:2020-06-09 09:48:35      阅读:64      评论:0      收藏:0      [点我收藏+]

标签:style   重复数   group   having   ble   sel   nbsp   重复   class   

delete from table where
order_no in (select orderno from (select order_no as orderno from table group by order_no having count(order_no) > 1) a)
and id not in (select pid from (select min(id) as pid from table group by order_no having count(order_no) > 1 ) b)

 

mysql 删除某字段重复数据并保留id最小的数据

标签:style   重复数   group   having   ble   sel   nbsp   重复   class   

原文地址:https://www.cnblogs.com/xueyicanfei/p/13070331.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!