Creating a leaderboard from a mySQL table
21:53 09 Jul 2016

I have a mySQL table containing multiple entries from several users (identified by userid). A full row contains userid,location, species and weight. I want to have a leaderboard, containing heaviest weight and corresponding location for each user for a certain species.

I tried:

SELECT userid, location, f_weight_i FROM eac.catches WHERE f_weight_i = (SELECT MAX(f_weight_i) FROM eac.catches) AND species='32' GROUP BY userid ORDER BY f_weight_i

but it didn't return any rows.

I also tried this, and it returned the overall best weight:

SELECT userid, location, f_weight_i FROM eac.catches WHERE f_weight_i = (SELECT MAX(f_weight_i) FROM eac.catches)

How can I get greatest weights for each user, for every species?

mysql