1、 需求ide
要將base_info.name以wl_開頭的數據的status字段更新爲2優化
2、執行spa
Update base_infoci
Set a.status=2get
Where (select id from base_info where name like ‘%xx%’)it
執行時,提示1093錯誤,table
ERROR 1093 (HY000): You can't specify target table 't' for update in FROM clause 。class
mysql不支持修改一個表的時候子查詢不能是同一個表。date
3、 優化select
經過臨時表解決這個問題
方法一:
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