mysql query to update field to max(field) + 1
Try
UPDATE TABLE set field = ((SELECT selected_value FROM (SELECT MAX(field) AS selected_value FROM table) AS sub_selected_value) + 1) WHERE id in (1,3,5,6,8)
In order to get around the mysql-error-1093
, use a subquery/derived table/inline view:
UPDATE table
SET field = (SELECT x.max_field
FROM (SELECT MAX(t.field) + 1 AS max_field
FROM TABLE t
WHERE t.id IN (1,3,5,6,8) ) x)