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"))
网友评论