I’m using a LEFT JOIN to get top ranking post (ranks are in one table, post information in another) to get the top 4 ranked post published in the last two weeks. The way I’ve been able to get this information was just sorting by the top rank. However, I want my top 4 results to not appear in order of their ranking (voting.vote), but in order of their published date (entries.id). I’m not sure what the best way of doing this would be. Below is my SQL statement that currently works to display the top 4 ranked items in the timeframe.
$result = mysql_query("SELECT entries.permalink, entries.title, voting.vote FROM entries LEFT JOIN voting ON voting.id = entries.id WHERE date>='$twoweeks' ORDER BY voting.vote DESC LIMIT 4");
Is there a way I can get the 4 row result to then be ordered by the entries.id or do I need to just do this externally in php with arrays and such?
BELOW EDIT IS SOLUTION FROM INFO PULLED FROM COMMENTS.
SELECT *
FROM
(
SELECT
entries.permalink,
entries.title,
voting.vote,
entries.id
FROM entries
LEFT JOIN voting ON voting.id = entries.id
WHERE date>='$twoweeks'
ORDER BY voting.vote DESC
LIMIT 4
) t
ORDER BY id;
Try this: