mysql update from n to 100 1

mysql update from n to 100

SET @rank:=0;
update tablename
set fieldname =@rank:=@rank+1;


UPDATE tablename
JOIN (SELECT @rank := 0) r
SET fieldname=@rank:=@rank+1;

Here is what the above code is Doing:
1. The first line is declaring a variable @rank and setting it to 0.
2. The second line is updating the fieldname column in the tablename table.
3. The third line is incrementing the @rank variable by 1.
4. The fourth line is joining the tablename table with the @rank variable.
5. The fifth line is setting the fieldname column to the value of the @rank variable.

Similar Posts