MySQL UPDATE UPDATE with ORDER BY and LIMIT

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

If the ORDER BY clause is specified in your update SQL statement, the rows are updated in the order that is specified.

If LIMIT clause is specified in your SQL statement, that places a limit on the number of rows that can be updated. There is no limit, if LIMIT clause not specified.

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.



Got any MySQL Question?