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

前端 未结 11 1232
迷失自我
迷失自我 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:47

    Add an id (or other key) to the table, and update where id (or key) = id (or key) of changed row.

    Of course, you'll have to make sure that either there are no duplicate display_order values, or that you're OK with ties in display_order displaying in any order, or you'll introduce a second, tie-breaker to the order by list.

提交回复
热议问题