Question

Je veux saisir seulement le dernier message de tous les sujets dans une catégorie (catégorie-> Forum-> tualiser> Post) à partir d'une base de données de phpbb en une seule requête. À l'heure actuelle, j'ai cuisiné, mais il ne retourne que le premier message, pas le dernier.

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

Quelqu'un sait comment faire correctement cela?

Était-ce utile?

La solution

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 (…)
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top