I have two tables. One "user" and one "votes", each user can have n votes. Now I select a list of users and output it. It works well with votes as COUNT in a LEFT JOIN, but now I want to calculate the RANK (1st, 2nd, 3rth, ...) of the user.
Theoretically very easy with ORDER BY Votes, but I also allow my users to SORT BY user date (when they joined). And I also have a pagination with a LIMIT in my query. So how do I solve this as best?
$user_sql = $db->query("SELECT u.*, COUNT(v.voteId) AS user_votes
FROM cs_users AS u
LEFT JOIN cs_users_votes AS v
ON u.userId = v.voteUserId");
(Basic query, but with pagination and sorter ORDER BY / LIMIT etc. will be added)
Hope you can help!