以下查询从数据库中选择子论坛以及每个子论坛中的最后一篇文章。
SELECT
    forums.*,
    MAX(posts.id),
    posts.title AS lastmsgtitle,
    posts.timee AS lastmsgtime,
    posts.useraid AS lastmsguseraid,
    posts.useradn AS lastmsguseradn,
    users.photo AS lastmsgphoto
FROM forums
    LEFT JOIN posts
        ON(posts.forumid = forums.id)
    LEFT JOIN users
        ON(posts.useraid = users.id)
WHERE forums.relatedto='$forumid'
    and posts.type='post'
GROUP BY forums.id
ORDER BY `id` DESC
唯一的问题,查询没有选择最后一个帖子,有什么想法吗?
论坛1
帖子2