Forum Moderators: open
SET @row_number_old :=0;
SELECT p.id, p.name, f.id, f.others, s.value, s.old_value, (
@row_number_old := @row_number_old +1
) AS old_position
FROM profile p
INNER JOIN other_table f ON f.profile_id = p.id
INNER JOIN score s ON s.profile_id = p.id
WHERE 1
ORDER BY old_value DESC While it is also possible both to set and to read the value of the same variable in a single SQL statement using the := operator, this is not recommended. Section 8.4, “User-Defined Variables”, explains why you should avoid doing this.