mysql update limit 限制更新条数正确写法

mysql更新时,要更新符合条件的记录中某个区间的数据,我们可能会行到使用limit取多少条,如何正确update呢?

用LIMIT只能限制更新多少条!测试如下:

update tb_planconfig set Circle=6 
where PlayType='xxx' and Circle=1 
order by RAND() desc 
limit 0,200;

上面这句测试了是错误的,MYSQL的UPDATE语句不能更新限制从第几条到第几条!

错误提示:> 1064 – You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘200’ at line 1

因为上面的limit写法有误,提示mysql不支持如此语法!

只能用下面这样的语句了,要么你就用where条件语句来限制了!

update tb_planconfig set Circle=6 
where PlayType='xxx' and Circle=1 
order by RAND() desc 
limit 200;

换一个语法写法就可以成功update了,你学到了吗,希望能帮助到你!

(0)
上一篇 2022年3月21日
下一篇 2022年3月21日

相关推荐