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

后端 未结 4 1523
无人共我
无人共我 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:31

    There are two (slightly different) syntaxes for deleting from mutliple tables. Here's the one without USING:

    DELETE a
    FROM 
          table_a AS a 
      INNER JOIN 
          table_b AS b
        ON  b.code = a.code
        AND b.id   = a.b_id   
    WHERE 
          a.object_id = 1 
      AND a.code = 'code' 
      AND b.`table` = 'testTable'   --- Do you actually have a column named "table"?
    

提交回复
热议问题