Mysql update語句賦值巢狀select

2021-09-01 15:58:17 字數 472 閱讀 5765

update a set col=(select col from a where id='5') where id>5 and id<10;

報錯了error 1093 (hy000): you can't specify target table 'a' for update in from clause

發現是 mysql 定義update語句不能同時對同一張進行set 賦值操作,也就是說

update a 的時候 不能在後面select col from a ,如果是不同表操作是沒有問題的。

解決方法:將select那裡的a的表起乙個別名b 就可以解決這個問題

update a set col=(select col from (select * from a ) as b where id='5' )where id>5 and id <10;

MySQL update語句流程總結

廢話不多說先來張 釋 update t set value value 1 where id 2 複製 我想可能大部分人看完這圖,思考片刻,接下來的就不需要在繼續看了,但是考慮到部分朋友還是新手 包括自己 以及後面複習,還是稍微嘮叨一段。首先,上圖中深色背景的表示在執行器中執行,也就是server層...

Mysql Update語句的詳細用法

以下的文章主要介紹的是mysql update 語句的實際用法,我們首先是以單錶的update語句來引出實現mysql update 語句的實際方案,以下就是文章的詳細內容描述,望你看完之後會有收穫。單錶的mysql update語句 update low priority ignore tbl n...

mysql update語句與limit的結合使用

mysql的update語句只支援更新前多少行,不支援從某行到另一行,比如 update tb name set column name test order by id asc limit 30 更新前30行的某個字段內容,沒什麼問題。update tb name set column name ...