MySQL 1093 You can't specify target table for update in FROM c 的解决办法

/* [Err] 1093 - You can't specify target table 't' for update in FROM clause */

update t_area set parent_name = (select name from t_area where parent_id = id);

执行SQL语句时出现这个错误。原因是在更新这个表和数据时又查询了它,而查询的数据又做了更新的条件。以前ORACLE上面没有这个错误。


解决方法:

把要更新的几列数据查询出来做为一个第三方表,然后筛选更新。

--ok

update t_area t set t.parent_name = (select t2.name from (select * from t_area) t2 where t.parent_id = t2.id);

参考资料:

1、MySQL - 1093异常 - You can’t specify target table ‘t’ for update in FROM clause
https://www.cnblogs.com/nick-huang/p/4412818.html

2、 [Err] 1093 - You can’t specify target table ‘s’ for update in FROM clause
https://blog.csdn.net/yaerfeng/article/details/7876461

3、You can’t specify target table ‘NAME’ for update in FROM clause
https://stackoverflow.com/questions/17742214/you-cant-specify-target-table-name-for-update-in-from-clause

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值