I have a update to fix positions values inside a table. The update worked fine in MYSQL 5.5, but after upgrade to MYSQL 5.7 it doesnt work anymore. Now, the "order by" inside the derived table is ignored. So, the rows are updateds based in primary key, not in order by.
May someone help me? Why the order by is ignored in MYSQL 5.7 and how to fixed it?
Thanks!!!
OLD POSITION VALUES
ImageId Position
389 0
390 6
391 4
392 1
NEW POSITION VALUES, AFTER FIXED (MYSQL 5.5)
ImageId Position
389 1
390 4
391 3
392 2
NEW POSITION VALUES, AFTER FIXED (MYSQL 5.7)
ImageId Position
389 1
390 2
391 3
392 4
UPDATE
UPDATE Image as t1
INNER JOIN (
SELECT t.*, @rownum := @rownum + 1 AS newPosition
FROM Image t, (SELECT @rownum := 0) r
ORDER BY t.Position
) as td
ON t1.ImageId = td.ImageId SET t1.Position= td.newPosition