Updating display order of multiple MySQL rows in one or very few queries

前端 未结 11 1331
迷失自我
迷失自我 2021-02-01 07:43

I have a table with say 20 rows each with a number for display order (1-20).

SELECT * FROM `mytable` ORDER BY `display_order` DESC;

From an adm

11条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-01 07:53

    You could create a temporary table and populate with the primary key of the rows you want to change, and the new values of display_order for those rows, then use the multi-table version of UPDATE to update the table in one go. I wouldn't assume that this is faster, however, not without testing both approaches.

提交回复
热议问题