I am having a MySQL query like this:
SELECT * FROM (
SELECT ranking_id, target_page_plain, ranking_date
FROM keywords_rankings
WHERE keyword_id = xxx
AND target_page_plain IS NOT NULL
ORDER BY ranking_date DESC, ranking_position ASC
) a
GROUP BY target_page_plain
ORDER BY ranking_date DESC
Since some MySQL version change, this does not work anymore like expected. This part here:
SELECT ranking_id, target_page_plain, ranking_date
FROM keywords_rankings
WHERE keyword_id = xxx
AND target_page_plain IS NOT NULL
ORDER BY ranking_date DESC, ranking_position ASC
will return the results correctly:
Now with the ORDER and GROUP BY, i want to get 2 rows, with the latest ranking_date.
What i expect would be:
- URL A / 2023-06-12
- URL B / 2023-02-06
But what i get is this:
- URL A / 2022-07-04
- URL B / 2022-08-15
Its not returning the grouped by URL with the order ORDER BY ranking_position DESC.
Its really strange, maybe someone can help.
Thanks