In a web game there is a ranking of the top points games played of the month:// QUERYSELECT * FROM gameWHERE date >= date_sub(CURDATE(),INTERVAL 1 MONTH)ORDER BY points DESC limit 0, 20But, in that case one player can be the top 1,2,3... so I have changed the query to add a distinct, and then only appears one game for player (the game with max points):// Query that filters player namesSELECT g.*FROM game gINNER JOIN ( SELECT playerName, MAX(points) AS MaxPoints             FROM game             GROUP BY playerName           ) groupGame        ON g.playerName = groupGame.playerName AND g.points = groupGame.MaxPoints WHERE date >= date_sub(CURDATE(),INTERVAL 1 MONTH)ORDER BY points DESC limit 0, 20The query works OK but the second query is much slower than the first. Is there any way to optimize it?
Query of top players of the month
mysql;sql
You will have to test performance, but a GROUP BY should help:SELECT playerName, MAX(points) AS points /*[, other columns]*/FROM gameWHERE date >= date_sub(CURDATE(),INTERVAL 1 MONTH)GROUP BY playerName /*[, other columns]*/ORDER BY points DESCLIMIT 0, 20