
October 11th, 2012, 11:41 PM
|
|
Registered User
|
|
Join Date: Oct 2012
Posts: 4
Time spent in forums: 23 m 22 sec
Reputation Power: 0
|
|
|
UPDATE Statment with Nested SELECT
Hi All,
I am fairly new to MySQL -- my issue is I need to update a Column based on the Column added from a Select statement:
Is this even possible to do? Here is the Select statement that I run and gives me the values I need. I then have the Update statement that has the two columns I need to match after the Select Statement is run:
SET @rownum = 0, @rank = 1, @prev_val = NULL;
SELECT *,@rownum := @rownum + 1 AS row
, @rank := IF(@prev_val!=Score,@rownum,@rank) AS rank
, @prev_val := Score AS score
FROM dbname.tablename
WHERE idGame = 1
ORDER BY Score DESC;
UPDATE dbname.tablename
SET tablename.Rank = tablename.rank
Thanks so much!
-Ryan
|