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?

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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.