I can’t figure this out, there are many examples here on stack overflow but there are differences in each one, and they are all giving the same problem.
I’ve got a list of 80 “slides” which have a column named “order”. Order is a number, currently ranging from 0 to 79.
If we delete a slide, we need to adjust the slides following that one, which I’ve already worked out the algorithm for.
Here is the result of the algorithm:
UPDATE cms_slides SET order =
CASE order
WHEN 68 THEN 67
WHEN 69 THEN 68
END CASE
WHERE order BETWEEN 68 AND 69
This is current code is based on Soulmerge’s solution here: Updating display order of multiple MySQL rows in one or very few queries
The column “order” does in fact reside in “cms_slides”, and the values 1 through 69 all exist under “order”.
THe error message is the typical: ERROR: You have an error in your SQL syntax; check the manual…
Does anyone know what is wrong with the code? I have tried many variations but none work, it’s probably something simple.
ORDERis a reserved word in MySQL you should use backticks around it and you do not need theEND CASEjust useEND: