Last active
August 9, 2016 12:32
-
-
Save gekh/11bac0278a010ccf8ca43d31a58766e3 to your computer and use it in GitHub Desktop.
Перемещние элементов в упорядоченном списке в БД одним запросом
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UPDATE `table_name` SET `order` = | |
CASE | |
WHEN `order` = 6 THEN 3 | |
ELSE `order` + 1 | |
END | |
WHERE `order` BETWEEN 3 AND 6; | |
--Переместить элемент с весом 6 на место элемента с весом 3. | |
--Изначально при вставке (INSERT) полю order присваиваем insert_id() чтобы оно было уникальным. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment