UPDATE with ORDER BY and LIMIT
suggest changeIf the ORDER BY clause is specified in your update SQL statement, the rows are updated in the order that is specified.
A LIMIT clause caps how many rows are updated. Without LIMIT, every row that matches is updated.
ORDER BY and LIMIT cannot be used for multi table update.
Syntax for the MySQL UPDATE with ORDER BY and LIMIT is,
UPDATE [ LOW_PRIORITY ] [ IGNORE ]
tableName
SET column1 = expression1,
column2 = expression2,
...
[WHERE conditions]
[ORDER BY expression [ ASC | DESC ]]
[LIMIT row_count];
---> Example
UPDATE employees SET isConfirmed=1 ORDER BY joiningDate LIMIT 10;
In the above example, 10 rows will be updated according to the order of employees joiningDate.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents