Reset SQL variable inside SELECT statement
- by Jason McCreary
I am trying to number some rows on a bridge table with a single UPDATE/SELECT statement using a counter variable @row. For example:
UPDATE teamrank JOIN (SELECT @row := @row + 1 AS position, name FROM members)
USING(teamID, memberID) SET rank = position
Is something like this possible or do I need to create a cursor? If it helps, I am using MySQL 5.