Generally we use SELECT MAX(datetime) with GROUP BY(page_ID) to get the most recent pages but I don’t understand why it doesn’t work here.
My following query should only select rows ID 75 and 77 but its selects 75 and 76 :

SELECT ru.page_ID AS id,
pFrom.name AS name,
UNIX_TIMESTAMP(ru.rating_time) AS action_date,
ru.current_rank AS current_rank,
MAX(ru.rating_time)
FROM ranks_update ru
INNER JOIN pages pFrom
ON ru.page_ID = pFrom.page_ID
WHERE ru.ranking_ID = :id_rk
AND ru.page_ID IN ( ** subquery 1 **)
AND ru.rating_time >= ( ** subquery 2 **)
GROUP BY ru.page_ID
ORDER BY ru.current_sum_vote DESC
1 Answer