-- vForumHierarchy,Threads SELECT * , cast( (prnt_DispOrd * 100 + ParentID) as char(4) ) TitleSeq , cast( (DisplayOrder * 100 + frum_ForumID) as char(4) ) ForumSeq FROM (Select frum.ForumId frum_ForumID ,frum.title frum_Title ,If(frum.ForumID=23, 60, frum.DisplayOrder) DisplayOrder ,frum.ThreadCount ,frum.ReplyCount frum_Reply_Count ,frum.LastPoster frum_LastPoster ,(from_unixtime(frum.lastpost)) frum_LastPostDate ,frum.Description frum_Description ,If(frum.ForumID=23, 22, frum.ParentID) ParentID FROM vb_Forum frum ) frum LEFT JOIN (SELECT prnt.ForumId prnt_ForumID ,prnt.title prnt_Title ,prnt.DisplayOrder prnt_DispOrd FROM vb_Forum prnt UNION SELECT (-1.) ForumId ,'DataFlex!' frum_Title ,0 DisplayOrder ) prnt ON frum.ParentID = prnt.prnt_ForumID LEFT JOIN ( SELECT thrd.ThreadID ,thrd.ForumID thrd_ForumId ,Replace(thrd.title,'--','-') as thrd_Title ,thrd.Open ,thrd.ReplyCount thrd_ReplyCount ,thrd.PostUserId ,thrd.PostUserName ,thrd.LastPoster thrd_LastPoster ,thrd.Attach Attachments ,thrd.DateLine thrd_DateLine ,(from_unixtime(thrd.dateline)) as thrd_DateStamp ,thrd.Views ,thrd.Visible FROM vb_thread thrd ) thrd ON thrd.thrd_forumid = frum.frum_forumid WHERE (frum.ParentID > 0 OR (frum.ParentID <0 and frum.ThreadCount > 0) ) and frum.frum_ForumID <66 and frum.frum_ForumID not between 45 and 49 and frum.frum_ForumID not between 61 and 63 and frum.frum_ForumID not IN (21, 27, 32, 34, 38, 39, 42, 44, 51, 56) and thrd.visible = 1 and thrd.thrd_dateline > 1100000000 and thrd.open < 10