Mysql update statement in conjunction with the limit of use

Sometimes the need to batch update data values ​​from the table how many rows to how many rows of a field

mysql update statement how many rows to update only supports, does not supported from a line to another line, such as
UPDATE tb_name SET column_name = 'test' ORDER BY id ASC LIMIT 30;

Update the content of a field of 30 lines before, no problem.


 

UPDATE tb_name SET column_name = 'test'
ORDER BY id ASC LIMIT 20,10; updated content from 20 lines to 30 lines of a field, this error.


 

The solution is to adopt the way subquery
UPDATE tb_name the SET column_name = 'the Test' in the WHERE id ( the SELECT id the FROM (the SELECT * the FROM tb_name the ORDER BY id ASC LIMIT 20,10) AS tt );
this can be achieved according to the updated table id the content of a field to the article 20, article 30, in ascending order of data

Guess you like

Origin www.cnblogs.com/xinruyi/p/11210720.html