You can't specify target table 'device' for update in FROM clause

delete from device where id =
(select d.id FROM device d LEFT JOIN river_chief rc on rc.river_id = d.river_id
LEFT JOIN chief c on c.id = rc.chief_id
WHERE c.user_id = ‘1’ AND d.id =’#’)

You can’t specify target table ‘device’ for update in FROM clause 因为直接到的device表中的id , 在mysql中无法直接通过这种方式操作, 需要通过中间表来操作。
delete from device where id in
(select a.id from
(select d.id FROM device d LEFT JOIN river_chief rc on rc.river_id = d.river_id
LEFT JOIN chief c on c.id = rc.chief_id
WHERE c.user_id = ‘1’ AND d.id =’c2ce10f7c59049fc8bb686866daf0ba4′) a
)

    原文作者:sakura_L
    原文地址: https://www.jianshu.com/p/bb469213cb6a
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞