chiprivers Posted January 7, 2007 Share Posted January 7, 2007 I have three tables containing details for a forum I am building, with columns including those listed below:Table: boardsColumns: boardID | boardTable: threadsColumns: threadID | boardID | thread_titleTable: postsColumns: postsID | threadIDOn the page that lists the discussion boards I would like to display the number of threads within each board and also the total number of posts. What would be the most efficient way to return these numbers? Quote Link to comment Share on other sites More sharing options...
chiprivers Posted January 7, 2007 Author Share Posted January 7, 2007 Is this right:SELECT count(*) AS c FROM posts, threads, boards WHERE posts.threadID = threads.threadID AND threads.boardID = boards.boardID Quote Link to comment Share on other sites More sharing options...
fenway Posted January 7, 2007 Share Posted January 7, 2007 Not unless you don't want the zero counts... try this (assuming I have the correct hierarchy):[code]SELECT count(posts.ID) AS c FROM boards LEFT JOIN threads ON ( threads.boardID = boards.boardID ) LEFT JOIN post ON ( posts.threadID = threads.threadID ) [/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.