I have the follwoing mysql table called user
user email count ranking
sss sss@gmail.com 111 0
ss ss@ggmail.con 11 0
s s@gmai.com 1 0
I try to use follwing mysql qyery to update the ranking
SET @r=0; UPDATE table user SET ranking= @r:= (@r+1) ORDER BY count ASC;
but it give me errors, I don’t know where I did wrong, any one could help me with that? thanks a lot!
errors:
SQL query:
UPDATE TABLE user SET ranking = @r := ( @r +1 ) ORDER BY count ASC ;
MySQL said:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'table user SET ranking= @r:= (@r+1) ORDER BY count ASC' at line 1
TABLEis a MySQL reserved keyword. Enclose it in backquotes when using it as an identifier, but in this case, it is unnecessary and should be removed.Note that 99% of the time, the error message will point exactly to the character or word in the query causing problems. Look to the first word after the
'in the error to start narrowing your problem.