Reset SQL variable inside SELECT statement

Posted by Jason McCreary on Stack Overflow See other posts from Stack Overflow or by Jason McCreary
Published on 2010-02-16T22:09:18Z Indexed on 2010/04/06 17:23 UTC
Read the original article Hit count: 193

Filed under:
|

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.

© Stack Overflow or respective owner

Related posts about sql

Related posts about mysql