2020-04-23
阅读量:
486
MySQL报错1093 you can't specify target table 'table2' for update in from clause
-- 所有产品名称中带荣耀的华为产品,将产品品牌更改为华为
update table2 set 品牌='华为' where 商品编码 in (select table1.商品编码
from table1
left join table2 on table2.商品编码=table1.商品编码
where 商品名称 like '%荣耀%');
运行上面代码,报错1093 you can't specify target table 'table2' for update in from clause

问题解答:
1093报错为修改一个表的时候子查询不能是同一个表,需要把子查询再套一层就可以了
可以把上述代码修改为如下的样子就可以了:
update table2 set 品牌='华为'
where 商品编码 in
(select 商品编码 from (select table1.商品编码 from table1
left join table2 on table1.商品编码=table2.商品编码
where 商品名称 like '%荣耀%') c);






评论(0)


暂无数据
推荐帖子
0条评论
0条评论
0条评论