删除 - 我无法指定目标表?

发布于 2024-11-04 00:18:53 字数 299 浏览 0 评论 0原文

为什么这个查询不起作用?

DELETE FROM recent_edits 
WHERE trackid NOT IN 
     (SELECT DISTINCT history.trackid 
     FROM history JOIN recent_edits ON history.trackid=recent_edits.trackid 
     GROUP BY recent_edits.trackid)

我收到此消息:“您无法在 FROM 子句中指定用于更新的目标表“recent_edits”

Why this query doesn't work?

DELETE FROM recent_edits 
WHERE trackid NOT IN 
     (SELECT DISTINCT history.trackid 
     FROM history JOIN recent_edits ON history.trackid=recent_edits.trackid 
     GROUP BY recent_edits.trackid)

I get this message : "You can't specify target table "recent_edits" for update in FROM clause

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦里的微风 2024-11-11 00:18:53

尝试用这种方法

DELETE FROM recent_edits 
WHERE trackid NOT IN 
     (select * from (SELECT DISTINCT history.trackid 
     FROM history JOIN recent_edits ON history.trackid=recent_edits.trackid 
     GROUP BY recent_edits.trackid) as t);

Try in this way

DELETE FROM recent_edits 
WHERE trackid NOT IN 
     (select * from (SELECT DISTINCT history.trackid 
     FROM history JOIN recent_edits ON history.trackid=recent_edits.trackid 
     GROUP BY recent_edits.trackid) as t);
谁的新欢旧爱 2024-11-11 00:18:53

您无法对锁定删除的表进行后处理。正如 Nicola 所说,使用 hack select * from (query) 将生成一个临时表而不是直接访问。

编辑 - 确保为您使用的表提供 ID,因为它是嵌套的,并且每个表都需要 uniqueID。

You can't post-process a table which is locked for deletion. using the hack select * from (query) as Nicola states will generate a temporary table instead of direct access.

Edit - make sure that you give ID to the tables you use since it is nested and will require uniqueID for every table.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文