首页 > 数据库技术 > 详细

mysql:error 1093 update子查询

时间:2017-12-22 19:38:55      阅读:238      评论:0      收藏:0      [点我收藏+]
一、 需求

要将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子查询

原文:http://blog.51cto.com/2338053/2053706

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!