I have a mySql table like this (simplified)
Id*| Text | Pos (integer)
-----------
A | foo | 0
B | bar | 1
C | baz | 2
D | qux | 3
Now, after I delete a row, I want to update the Pos value on the remaining rows so that no "holes" or gaps are to be found.
For example if I row with Id='C' is deleted, the remaing table should be:
Id*| Text | Pos (integer)
-----------
A | foo | 0
B | bar | 1
D | qux | 2
Is this possible in a single query?
UPDATE Based on the accepted answer this was the solution to my problem:
START TRANSACTION;
SELECT @A:=pos FROM table_name WHERE Id= 'C';
DELETE FROM table_name WHERE Id = 'C';
UPDATE table_name SET Pos = Pos - 1 WHERE Pos > @A;
COMMIT;