I've written a forum which has a topics table and a posts table and I'm trying to get five recent topics and the last post in each topic in one query.
You can see what I have at http://www.comeplaydying.com/
For the most part it's working, the problem I am trying to solve is that I only want each topic to show up once, but what's happening is mysql is returning the last five posts and matching them with their topics when i want the last five topics to be matched with posts.
Here is the query I'm using for the page as it is now.
SELECT topics., posts., forums.forumid, forums.name, users.username
FROM topics, forums
LEFT JOIN users ON users.userid=topics.userid
LEFT JOIN posts ON topics.topicid=posts.parentid
WHERE topics.topicid>0 AND forums.forumid=topics.forumid
ORDER BY topics.timestamp DESC, posts.posted DESC
LIMIT 0,5
You would think, since I'm SELECTing from topics and JOINing on posts it would get topics and match posts to them but no such luck. Does anyone have any ideas for this?