I have a SQL statement that I'm trying to run, but it's throwing an error:
SELECT fp.forum_id, COUNT(fp.forum_id) AS num_postsFROM forums_posts fpGROUP BY fp.forum_idWHERE ( SELECT COUNT(p.post_id) AS num_joined_posts FROM posts p WHERE p.post_type IN ('TypeA', 'TypeB', 'TypeC') AND p.forum_id = fp.forum_id) > 0ORDER BY num_posts DESC
The forums_posts
table is a relational table matching forum IDs to post IDs, and the posts
table (which also stores the post's forum ID) just contains info about each post. I am trying to find out: which forums have posts of the type TypeA, TypeB, or TypeC; and how many posts are in each of those forums.
Nested SQL statements have never been my strong suit. Can somebody point out the correct way to go about doing this? Thanks.