MySQL:您无法指定目标表“任务”用于 FROM 子句中的更新
我在运行以下查询时遇到 MySQL 错误“您无法在 FROM 子句中指定要更新的目标表“任务””:
DELETE FROM tasks
WHERE tasks.id IN
(
SELECT tasks.id
FROM tasks
JOIN deadlines ON deadlines.id = deadline_id
WHERE DATE_ADD(tasks.created_at, INTERVAL deadlines.duration DAY) <= NOW()
)
我该如何管理此问题?
谢谢!
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 IN
(
SELECT tasks.id
FROM tasks
JOIN deadlines ON deadlines.id = deadline_id
WHERE DATE_ADD(tasks.created_at, INTERVAL deadlines.duration DAY) <= NOW()
)
How can I manage this?
Thanx!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将其包装在子查询中,如下所示。问题是 MySQL 无法更新它也在查询的行。这将使 MySQL 隐式地使用临时表来存储要删除的 id。
You can wrap it in a subquery like so. The issue is that MySQL can't update rows that it's also querying. This will make MySQL use a temporary table implicitly to store the ids you want to delete.
这是因为您多次指定任务表。尝试:
It's because you're specifying the tasks table more than once. Try: