Feb. 28, 2013, 10:52 a.m.
IT

MySQL update of numeric field with sequential number

Suppose you have a table as follow:

NameId
John
Peter
George

and you want to update the Id field with a sequential rank 1,2,3,4,... In MySQL this is a way to do so:

set @rank := 0; update T set Id = @rank:=@rank+1;

The table will look like this:

NameId
John1
Peter2
George3