MySQL / MariaDB working only sometimes I have the following code in MariaDB that was working perfectly well yesterday. It calculates a rank and orders by the data by another column:
SET @c = (SELECT COUNT(*) FROM myTable);
SET @rownum = 0;
UPDATE myTable
SET rank = (100 / @c) * (@rownum:= 1 + @rownum)
ORDER BY anotherColumn DESC LIMIT 100000;

Today I executed it and the first time through it gave the wrong ranking values. I don't think the SET @rownum = 0 had worked. Now it seems to be working fine again.
Does anyone know why it would work perfectly yesterday and then stop working today and behave so strangely?
EDIT: I believe the @c is the variable that isn't updating when I add a new row. Does anyone know how to force it to recalculate @c based on the current data in the table?
MariaDB 5.2 is really old.  Upgrade.
MariaDB 10.2 (and MySQL 8.0) have RANK and other &quot;windowing functions&quot; to assist with your query.
Setting @variables inside SELECTs should not be trusted.  Rewrite the query to avoid them.
Updating everyone's rank all the time will be a performance drag when you have a lot of users.