SELECT forum.*, thread.title as thtitle FROM forum LEFT OUTER JOIN thread on thread.forumid = forum.forumid and thread.lastpost >= (forum.lastpost-30) WHERE displayorder<>0 AND active=1 ORDER BY parentid,displayorder