MySQL | You can't specify target table 'a' for update in FROM clause

后端 未结 4 1525
无人共我
无人共我 2021-01-16 04:14
DELETE FROM table_a WHERE id IN(
    SELECT table_a.id AS id FROM table_a, table_b 
    WHERE table_a.object_id = 1 AND table_a.code = \'code\' 
        AND table_a.         


        
4条回答
  •  悲&欢浪女
    2021-01-16 04:30

    This is a common MySQL issue, use a temporary table between the select and update/delete:

    DELETE FROM table_a WHERE id IN 
       (select id from 
           (SELECT table_a.id AS id FROM table_a, table_b 
            WHERE table_a.object_id = 1 
            AND table_a.code = 'code' 
            AND table_a.code = table_b.code 
            AND table_b.id = table_a.b_id 
            AND table_b.table = 'testTable')
        ) tempTable
    

提交回复
热议问题