//mysql删除两条或两条以上相同的数据并保留其中最小的一条

DELETE FROM `lm_callback_6-1`
WHERE order_no IN ( select a.order_no from (SELECT order_no FROM `lm_callback_6-1` GROUP BY `order_no` HAVING count( order_no ) > 1) a)
AND
id NOT IN (select a.id from (SELECT  min(id) as id FROM `lm_callback_6-1` GROUP BY `order_no` HAVING count( order_no ) > 1) a)

你可能感兴趣的:(mysql,数据库,mybatis)