Hey guys, I'm fairly proficient with sql but i've run into something that i can't seem to get into a single query. Here is the dilema:
I have 3 tables with are linked like so
Table1:
Table1_ID
Table1_Value
Table2:
Table2_ID
Table1_ID
Table2_Value
Table3:
Table3_ID
Table2_ID
Table3_Value
I want to select the Value from Table 1 and the count of all the records in table 2 that have the same id as table 1 from table 2, as well as the count of the records that have the same id as table 2 from table 3. ie.
TABLE1VALUE, COUNT(FROM2 WHERE ID=TABLE1ID), COUNT(FROM3 WHERE ID=TABLE2ID)
I was trying this query but it doesn't seem to work
SELECT forums.Forum_NAME, count(topics.Topic_ID), count(posts.Post_ID)
from forums
inner join topics
on forums.Forum_ID=topics.Forum_ID
inner join posts
on topics.Topic_ID=posts.Topic_ID
group by forums.Forum_NAME;
Can anyone give me some suggestions? The field names in the code above are the field names from the db.