updating columns with a sequence number mysql

Viewed 53478

I have a table with the columns: (this is only an example I have 50K records)

Name,   Number

Joe     Null
Michael Null
Moses   Null

I to update the number with a sequence number from 1-3 so it will look like this:

Name,   Number

Joe     1
Michael 2
Moses   3

How can I do it in SQL for Mysql in one SQL command

5 Answers
update `table_name` set `Number`=@rank:=@rank+1

This will be done. Thanks

Using above two solutions I made this query and it worked.

SET @rank=0;update emp_data set empfk_id = @rank:=@rank+1;

Related