美文网首页
Mysql 1093 错误

Mysql 1093 错误

作者: 五岁小孩 | 来源:发表于2020-07-29 14:51 被阅读0次

1093

错误

 ~~~mysql

update from xj_tab set age='18' where id=(select id from xj_tab where name="xj")
Mysql 1093 - You can't specify target table 'xxx' for update in FROM clause
~~~

原因

update语句中包含的子查询的表和update的表为同一张表时,
报错:1093-You can’t specify target table for update in FROM clause
mysql不允许update目标表和子查询里面的表为同一张表

解决

#利用子查询sql可以改变双层的子查询,即可执行成功 
# (但性能较差,仅仅适合较小的数据量的)
#sql语句修改后:
update from xj_tab set age='18' where id=(select id from (select id from xj_tab where name="xj"))

相关文章

网友评论

      本文标题:Mysql 1093 错误

      本文链接:https://www.haomeiwen.com/subject/ryzfrktx.html