Hello!
This is what i\'m trying to do:
I have two tables:
forum_topic and forum_message.
forum_message.topicid FK[forum_topic.id]
I\'m supposed to show a list of all topics and indicate how many answers there are to the topics:
-Name---Answers
Topic 1 (0)
Topic 2 (20)
Topic 3 (50)
Since some topics don\'t have any answers yet, I\'ve done a \"left outer join\" to include
those topics as well. The problem arises as
the list also should exclude some topics due to authorization limits...
There is a column in [forum_topic] that indicates this [forum_topic.closed]. This column whill have a value of \"yes\" if the topic should be excluded from the list and \"no\" otherwise.
Below is the query I use to extract the information. The problem has something to do with the \"left outer join\". When present, it includes all topics regardless of the value of [forum_topic.closed]. I don\'t want to exclude the topics \"by hand\"... there must be another way of expressing this query so that it excludes the closed topics.
Please help!
SELECT COUNT(forum_message.id) as num_messages, forum_topic.id, forum_topic.name, forum_topic.created, forum_topic.createdby, forum_topic.closed
FROM forum_topic LEFT OUTER JOIN forum_message
ON forum_topic.id = forum_message.topicid AND forum_topic.closed = \'no\'
GROUP BY forum_topic.id;
Any help would be of great help!
(sorry for my SWEnglish)