MySQL - Save list order with single update

Можно ли отсортировать список и сохранить порядок в одном обновлении?

Я пробовал этот способ:

UPDATE `jos_vm_category`,(SELECT @row:=0) AS init SET @row:=@row+1, list_order=@row ORDER BY `category_name` ASC

, но получил ошибка:

1221 - неправильное использование UPDATE и ORDER BY

If it's not clear, I need this:

category_id | category_name | list_order
    3       |       A       |       1
    1       |       B       |       2
    2       |       C       |       3

from this:

category_id | category_name | list_order
    1       |       B       |       1
    2       |       C       |       2
    3       |       A       |       3

with a single UPDATE.

So list_order is a field of the table where I have to save the order of rows. (I already have the solution, but have to wait for 2 days, so I'll publish then if nobody answers the question.)

8
задан Álvaro González 27 November 2013 в 17:23
поделиться