本节内容:
mysql/ target=_blank class=infotextkey>mysql数据库中update语句赋值嵌套select
例句:
复制代码 代码示例:
update a set col=(select col from a where id='5') where id>5 and id<10;
报错:
ERROR 1093 (HY000): You can't specify target table 'a' for update in FROM clause
原因分析:
mysql 定义update语句不能同时对同一张进行set 赋值操作,即:
update a 时 不能在后面select col from a ,如果是不同表操作则无此问题。
解决方法:
复制代码 代码示例:
update a set col=(select col from (select * from a ) as b where id='5' )where id>5 and id <10;
将select中a的表起一个别名b,即可解决:
复制代码 代码示例:
update mem_player set `DataWarehouse`=(select `DataWarehouse` from (select * from mem_player) as b where `Pid`=100000)