I'm trying to update users' rankings in a single query but it crashes with this error:
ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'UPDATE users SET rank = @r:= (@r+1) ORDER BY score DESC' at line 1
Is there anything wrong with my query?
SET @r=0;UPDATE users SET rank = @r:= (@r+1) ORDER BY score DESC
I got the query from this answer
I'm executing this query on a node.js mysql library.
db.query('SET @r=0;UPDATE users SET rank = @r:= (@r+1) ORDER BY score DESC', function(err){
if (err){
console.log(err);
return;
}
console.log("Ranking updated successfully.");
});