Jump to content

Intermiediate query assistance required please


chiprivers

Recommended Posts

I have three tables containing details for a forum I am building, with columns including those listed below:

Table: boards
Columns: boardID | board

Table: threads
Columns: threadID | boardID | thread_title

Table: posts
Columns: postsID | threadID

On 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?

Link to comment
Share on other sites

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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.