Answer the question
In order to leave comments, you need to log in
MySQL. How to count the number of topics created in a certain forum category?
Category table structure (forum_categories):
+----+-----------+---------------------+--------------+----------+
| id | parent_id | name | allow_topics | position |
+----+-----------+---------------------+--------------+----------+
| 1 | NULL | Жизнь сайта | 0 | 1 |
| 2 | 1 | Конкурсы | 1 | 1 |
| 3 | 1 | Вопросы/Предложения | 1 | 2 |
+----+-----------+---------------------+--------------+----------+
+----+-------------+---------+-------------+--------+--------+---------------------+---------------------+------------+
| id | category_id | user_id | title | pinned | locked | created_at | updated_at | deleted_at |
+----+-------------+---------+-------------+--------+--------+---------------------+---------------------+------------+
| 1 | 2 | 1 | FIRST TITLE | 0 | 0 | 2016-01-18 08:03:53 | 2016-01-18 08:03:53 | NULL |
+----+-------------+---------+-------------+--------+--------+---------------------+---------------------+------------+
Answer the question
In order to leave comments, you need to log in
select count(t.id) as cnt, c.* from forum_categories c
join forum_topics t ON t.category_id = c.id
group by t.category_id
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question