UPDATE some_table set rank=1 WHERE id=25
UPDATE some_table set rank=2 WHERE id=15
UPDATE some_table set rank=3 WHERE id=10
UPDATE some_table set rank=4 WHERE id=12
UPDATE some_table set rank=5 WHERE id=13
UPDATE some_table set rank=6 WHERE id=14
UPDATE some_table set rank=7 WHERE id=11
How can I turn this into a single query because I couldn’t think of one? These values of id are in sequence. Think of a photo gallery that has images and the user can opt to re-arrange the sequence of these images. The back-end will assign the ranks based from the user-defined sequence and will be used in the ORDER BY clause.
1 Answer