mysql update語句與limit的結合使用

2021-08-10 12:46:17 字數 492 閱讀 5799

mysql的update語句只支援更新前多少行,不支援從某行到另一行,比如

update tb_name set column_name='test' order by id asc limit 30;

更新前30行的某個字段內容,沒什麼問題。

update tb_name set column_name='test' order by id asc limit 20,10;

更新從20行到30行的某個欄位的內容,這樣會報錯。

解決辦法就是採用子查詢的方式

update tb_name set column_name='test' where id in (select id from (select * from tb_name order by id asc limit 20,10) as tt);

這樣就能實現更新表中根據id公升序排序的第20條到第30條資料的某個欄位的內容

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語句賦值巢狀select

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 發現是 ...