首页 > 数据库 >mysql出现 You can't specify target table 'xx' for update in FROM clause 0.000 sec

mysql出现 You can't specify target table 'xx' for update in FROM clause 0.000 sec

时间:2023-02-20 18:58:23浏览次数:49  
标签:语句 target clause update BillId outorder where select

在执行如下更新语句的时候,提示如下问题: You can't specify target table 'outorder' for update in FROM clause 0.000 sec, 大体翻译出来的意思是: 不能先select出同一表中的某些值,再update这个表(在同一语句中)
update outorder set SchoolId = 5,canteenid = 4 where BillId in ( select BillId from outorder where CanteenId = 6 );
解决方案:将查询出来的数据集放在一个表中,类似如下语句
SELECT a.BillId FROM (select BillId from outorder where CanteenId = 6) a
最终的语句调整为如下格式
update outorder set SchoolId = 5,canteenid = 4 where BillId in ( SELECT a.BillId FROM (select BillId from outorder where CanteenId = 6) a );

标签:语句,target,clause,update,BillId,outorder,where,select
From: https://www.cnblogs.com/pfwbloghome/p/17138507.html

相关文章