MySQL: You can't specify target table 'tasks' for update in FROM clause

后端 未结 2 2001
粉色の甜心
粉色の甜心 2020-12-19 16:18

I have got MySQL error \"You can\'t specify target table \'tasks\' for update in FROM clause\" running the following query:

DELETE FROM tasks
WHERE tasks.id          


        
2条回答
  •  旧时难觅i
    2020-12-19 17:01

    It's because you're specifying the tasks table more than once. Try:

    DELETE FROM tasks
    USING deadlines
    WHERE deadlines.id = tasks.deadline_id
    AND DATE_ADD(tasks.created_at, INTERVAL deadlines.duration DAY) <= NOW()
    

提交回复
热议问题