MySQL - 当嵌套选择使用该表时如何从表中删除?
我正在尝试做这样的事情:
DELETE FROM table_1
WHERE table_1.id IN (SELECT table_1.id
FROM table_1,
table_2,
table_3
WHERE table_1.id = table_2.table_1_id
AND table_2.id = table_3.table_2_id
AND table_3.id = 5)
似乎 MySQL 不允许我在嵌套 SELECT 中拥有 table_1
。建议?
I'm trying to do something like this:
DELETE FROM table_1
WHERE table_1.id IN (SELECT table_1.id
FROM table_1,
table_2,
table_3
WHERE table_1.id = table_2.table_1_id
AND table_2.id = table_3.table_2_id
AND table_3.id = 5)
Seems like MySQL won't let me have table_1
in the nested SELECT. Suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能会收到此错误:
您应该能够使用 MySQL 的多表
DELETE
语法:上面的查询应该可以工作,但作为一般规则,我建议使用 ANSI JOIN 语法:
You're probably getting this error:
You should be able to do this using MySQL's multiple-table
DELETE
syntax instead:The above query should work, but as a general rule I would recommend using ANSI JOIN syntax instead: