当前位置:Gxlcms > 数据库问题 > mysql:error 1093 update子查询

mysql:error 1093 update子查询

时间:2021-07-01 10:21:17 帮助过:25人阅读

要将base_info.name以wl_开头的数据的status字段更新为2


二、执行


Update base_info

Set a.status=2

Where (select id from base_info where name like ‘%xx%’)

 

执行时,提示1093错误,

ERROR 1093 (HY000): You can't specify target table 't' for update in FROM clause 。

mysql不支持修改一个表的时候子查询不能是同一个表。


三、 优化

通过临时表解决这个问题

方法一:

Update base_info

Set a.status=2

Where id in ( select * from (select id from base_info where name like ‘%xx%’ ) tmp )

 

方法二:

update base_info b

join (select id from base_info where act_name like 'wlq_%') tmp

on tmp.id= b.id

set b.expand1=2


mysql:error 1093 update子查询

标签:update

人气教程排行