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
)