1

我只想在单个查询中从 phpbb 数据库中获取一个类别(类别->论坛->主题->帖子)中所有主题的最后一篇文章。目前我已经做了这个,但它只返回第一个帖子,而不是最后一个。

SELECT *, MAX(p.post_id)
FROM phpbb_forums f, phpbb_topics t, phpbb_posts p
WHERE f.parent_id IN (<categories>)
AND t.forum_id = f.forum_id
AND p.topic_id = t.topic_id
GROUP BY p.topic_id

有谁知道如何正确地做到这一点?

4

1 回答 1

3
SELECT  *
FROM    phpbb_forums f
JOIN    phpbb_topics t
ON      t.forum_id = f.forum_id
JOIN    phpbb_posts p
ON      p.post_id = 
        (
        SELECT  pi.post_id
        FROM    phpbb_posts pi
        WHERE   pi.topic_id = t.topic_id
        ORDER BY
                pi.date DESC
        LIMIT 1
        )
WHERE   f.parent_id IN (…)
于 2009-11-09T14:12:30.133 回答