Mysql 抛出错误
DELETE FROM mytable WHERE id IN (SELECT id FROM mytable where roll=1)
我有一个表mytable
。我的上述查询抛出错误。
您无法在 FROM 子句中指定要更新的目标表“mytable”
DELETE FROM mytable WHERE id IN (SELECT id FROM mytable where roll=1)
I have a table mytable
. My above query is throwing an error.
You can't specify target table 'mytable' for update in FROM clause
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
来自 MySQL 文档:
幸运的是,您不需要子查询。就这样做:
启动起来更短、更清晰。
From the MySQL documentation:
Fortunately, you don't need the subquery. Just do:
It's much shorter and clearer to boot.
你为什么不这样做呢?
Why don't you just do this?
你为什么不直接写呢
?
发生该错误的原因是,当上级查询修改同一个表时,MySql 不喜欢从子查询中的表中获取数据。
Why don't you just write
?
The error occurs because MySql doesn't like it to fetch form a table in a subquery when the superior query modifies the same table.
为什么不简单地:
Why not simply:
你为什么使用子查询?你可以这样写:
Why are you using subquery? You can write it this way:
此帖子解释了为什么您不能执行此操作。
在这个例子中,你可以使用:
This thread explains why you can't do this.
And in this example, you can just use: