クエリに関しては、クエリで取得して、次のようなものを使用してカテゴリのリストを取得できます。
select forum_categories.id, forum_categories.name, max( forum_answer.id ) as
from forum_categories
left join forum_questions on forum_questins.category_id = forum_categories.category_id
left join forum_answers on forum_answers.question_id = forum_questions.question_id
group by forum_categories.id, forum_categories.name
操作にかかる費用は、フォーラムの性質によって異なります。誰かが頻繁に投稿している場合、誰かが投稿するたびにカテゴリの列を更新すると、費用が高くなる可能性があります。人々がカテゴリのリストを頻繁にロードしている場合、結合はよりコストのかかる操作になる可能性があります。
また、以下からカテゴリリストを取得するためのビューを作成すると便利な場合があります。
create view category_list as
select forum_categories.id, forum_categories.name, max( forum_answer.id ) as latest_asnwer_id
from forum_categories
left join forum_questions on forum_questins.category_id = forum_categories.category_id
left join forum_answers on forum_answers.question_id = forum_questions.question_id
group by forum_categories.id, forum_categories.name
その後、テーブルであるかのようにアクセスできます。