去掉同一个表中重复的数据

 

You can't specify target table 报错的问题

 

 mysql> delete from 表1 where sms_send_uid in (

    -> select a.sms_send_uid from  表1 a where a.shop_uid='xxx' and a.send_time between '2017-05-14' and '2017-05-14 23:59:59' and a.status=0  

    -> and a.sms_send_uid not in ( select max(m.sms_send_uid)  from 表1 m where m.shop_uid='xxx' and m.send_time between '2017-05-14' and '2017-05-14 23:59:59' and m.status=0  group by m.mobile )

    -> );

ERROR 1093 (HY000): You can't specify target table '表1' for update in FROM clause

 

 修改未如下 就ok

delete from 表1  where sms_send_uid in (

扫描二维码关注公众号,回复: 287760 查看本文章

select x.sms_send_uid from (

select a.sms_send_uid from  表1 a where a.shop_uid='xxx' and a.send_time between '2017-05-14' and '2017-05-14 23:59:59' and a.status=0  

and a.sms_send_uid not in ( select max(m.sms_send_uid)  from 表1 m where m.shop_uid='xxx' and m.send_time between '2017-05-14' and '2017-05-14 23:59:59' and m.status=0  group by m.mobile )

) x

);

猜你喜欢

转载自fengbin2005.iteye.com/blog/2374293