MySQL :: 3.6.4 The Rows Holding the Group-wise Maximum of a Certain Field
The query that worked for me for my cycling community:
SELECT s1.user_id, distance, s1.date_logged FROM trips s1 JOIN (SELECT user_id, MAX(date_logged) AS date_logged FROM trips GROUP BY user_id ORDER BY date_logged DESC LIMIT 10) AS s2 ON s1.user_id = s2.user_id AND s1.date_logged = s2.date_logged LIMIT 10;
A 0.2 second query on ~120,000 rows, not too bad.
Loading...
