Remove duplicate data in the same table

 

You can't specify target table error

 

 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

 

 It is ok if the modification is not as follows

delete from 表1  where sms_send_uid in (

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

);

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326655423&siteId=291194637