All pastes #112018 Raw Edit

Unnamed

public text v1 · immutable
·published 2006-08-02 16:50 UTC
rendered paste body
SELECT f.id, f.minclassread, f.name, f.description, f.topiccount, f.postcount,
       (SELECT (COALESCE((SELECT lastpostread
                              FROM readposts
                              WHERE userid = 1132
                                AND topicid = t.id
                              LIMIT 1),
                          0) < t.lastpost)
                    AS t_newposts
              FROM topics t
              WHERE t.forumid = f.id
           ORDER BY t_newposts DESC
           LIMIT 1
        ) AS newposts,
        lp.topicid, t.subject, t.lastpost, lp.added, lp.userid, u.username
     FROM forums f
       LEFT OUTER JOIN posts lp
             ON lp.id = (SELECT lastpost
                            FROM topics
                            WHERE forumid=f.id
                          ORDER BY lastpost DESC
                          LIMIT 1)
       LEFT OUTER JOIN topics t
             ON t.id = lp.topicid
       LEFT OUTER JOIN users u
             ON u.id = lp.userid
   ORDER BY f.name