Looking at my old answer, I just thought of another way to solve the problem without the tmp table:
CREATE Table tbl (id int,grpid int, text varchar(10)); INSERT INTO tbl (id,text) VALUES (1,'NBA'),(2,'NBA'), (3,'NHL'),(4,'NHH'),(5,'NHL'),(8,'BAA'),(9,'BAA'); SET @i:=100;
tbl after UPDATE :
| ID | GRPID | TEXT | --------------------- | 1 | 102 | NBA | | 2 | 102 | NBA | | 3 | 104 | NHL | | 4 | 103 | NHH | | 5 | 104 | NHL | | 8 | 101 | BAA | | 9 | 101 | BAA |
sqlfiddle
source share