Consider a table that has a position
column. I like to renumber the position values so that each gets a unique value, starting with 1, and without gaps. The order does not matter.
I've tried this code:
UPDATE myTable SET position = (
SELECT MAX(position)+1 FROM myTable
)
But that sets all values to the same value. Apparently, MAX(position)
only gets evaluated once and not for every single updated row.
How do I make this work?
I've found a similar question where the solution is to use a separate table but I wonder if that's avoidable in my case.
Aucun commentaire:
Enregistrer un commentaire