您的位置:首页 > 数据库 > MySQL

mysql不能查询一个表然后更新它

2017-03-28 14:10 190 查看
MySQL 为什么不能在同一个表上查询和更新?

update table set x = (select y from table where id =1)
error 1093: you cant specify target table test for update in from clause

通常采用的解决方案
update table set x = select * from (select y from table where id =1) t

因为update会锁表,放入临时表就不会出现这样的问题
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐