mysql 删除重复行

1.删除user_id 和 add_time 相同的行

delete from t_park_customer_statistics
where id in (
select * from (
SELECT MAX(id) id FROM t_park_customer_statistics cs
GROUP BY cs.user_id,cs.add_time
HAVING COUNT(1)>1 ) t
)

 注意:子查询去掉外面一层的select回报如下错误 

错误代码: 1093
You can't specify target table 't_park_customer_statistics' for update in FROM clause

只有MYsql才会报错

DELETE FROM t_park_customer_statistics
WHERE id IN (
SELECT MAX(id) id FROM t_park_customer_statistics cs
GROUP BY cs.user_id,cs.add_time
HAVING COUNT(1)>1 
)

 

posted @ 2017-04-06 11:09  飞翔.  阅读(396)  评论(0编辑  收藏  举报