# How do I get a report of total topics by subcategory for all subcategories please?

**URL:** <https://meta.discourse.org/t/how-do-i-get-a-report-of-total-topics-by-subcategory-for-all-subcategories-please/235296>\
**Category:** Data & reporting\
**Tags:** sql-query\
**Created:** [August 6, 2022, 8:58am UTC](https://meta.discourse.org/t/how-do-i-get-a-report-of-total-topics-by-subcategory-for-all-subcategories-please/235296 "2022-08-06T08:58:09Z")\
**Posts on this page:** 7\
**Page:** 1

## AI-generated summary

The user [DGForum](/t/-/235296/1) asks for a report of total topics by subcategory across all time. [JammyDodger](/t/-/235296/2) suggests using the Data Explorer with a SQL query to retrieve the data, noting it excludes deleted or unlisted topics and accounts for the About topic. [DGForum](/t/-/235296/3) doesn't have Data Explorer but considers the solution. [JammyDodger](/t/-/235296/4) offers an alternative by manually noting numbers from the category dropdown, which [DGForum](/t/-/235296/5) initially finds insufficient due to display limitations but later confirms it works after understanding the method [6](/t/-/235296/6).

<div class="post-metadata">

**Author:** ![DGForum](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dgforum/32/277218_2.png) [@DGForum](https://meta.discourse.org/u/DGForum)\
**Post date:** [August 6, 2022, 8:58am UTC](https://meta.discourse.org/t/how-do-i-get-a-report-of-total-topics-by-subcategory-for-all-subcategories-please/235296/1 "2022-08-06T08:58:10Z")

</div>

Couldn’t find anything specific to my request please.

I’d just like to see total topics per subcategory for all time. It’s only been 3 years in our case.

Thank-you.

---

<div class="post-metadata">

**Author:** ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)\
**Post date:** [August 6, 2022, 11:34am UTC](https://meta.discourse.org/t/how-do-i-get-a-report-of-total-topics-by-subcategory-for-all-subcategories-please/235296/2 "2022-08-06T11:34:27Z")

</div>

Have you got the [data explorer](https://meta.discourse.org/t/discourse-data-explorer/32566) on your site? If so, you should be able to pull out those numbers with something like this:

```plaintext
SELECT t.category_id,
       COUNT(t.category_id)-1 AS topics
FROM topics t
JOIN categories c ON c.id = t.category_id
WHERE t.deleted_at IS NULL
AND t.visible = true
AND c.post_count IS NOT NULL
GROUP BY c.position, t.category_id
ORDER BY c.position

```

This one doesn’t count Unlisted or deleted topics, and ignores deleted categories based on NULL post count. It’s also in ‘position’ order, which may not be as useful if you haven’t set fixed postions.

(I’ve added in a ‘-1’ to account for the About topic)

---

<div class="post-metadata">

**Author:** ![DGForum](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dgforum/32/277218_2.png) [@DGForum](https://meta.discourse.org/u/DGForum)\
**Post date:** [August 6, 2022, 11:37am UTC](https://meta.discourse.org/t/how-do-i-get-a-report-of-total-topics-by-subcategory-for-all-subcategories-please/235296/3 "2022-08-06T11:37:15Z")

</div>

Don’t have [Data Explorer](https://meta.discourse.org/t/32566?silent=true), but investigating what you’ve shared.  
Thank-you.

---

<div class="post-metadata">

**Author:** ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)\
**Post date:** [August 6, 2022, 11:38am UTC](https://meta.discourse.org/t/how-do-i-get-a-report-of-total-topics-by-subcategory-for-all-subcategories-please/235296/4 "2022-08-06T11:38:59Z")

</div>

That replicates the numbers shown in the category dropdown list, so you could manually jot them down from there as a backup plan?

 ![image](https://global.discourse-cdn.com/meta/original/4X/9/a/0/9a078f314c7d70a06e92b883528a4668db5dcabd.png)     ![image](https://global.discourse-cdn.com/meta/original/4X/4/b/4/4b43201cdc747c42309e226e9dfff261986cd0f6.png)

---

<div class="post-metadata">

**Author:** ![DGForum](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dgforum/32/277218_2.png) [@DGForum](https://meta.discourse.org/u/DGForum)\
**Post date:** [August 6, 2022, 11:42am UTC](https://meta.discourse.org/t/how-do-i-get-a-report-of-total-topics-by-subcategory-for-all-subcategories-please/235296/5 "2022-08-06T11:42:50Z")

</div>

The drop down window is too narrow - category descriptions are longish.  
And it doesn’t give subcategories.

---

<div class="post-metadata">

**Author:** ![DGForum](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dgforum/32/277218_2.png) [@DGForum](https://meta.discourse.org/u/DGForum)\
**Post date:** [August 6, 2022, 11:58am UTC](https://meta.discourse.org/t/how-do-i-get-a-report-of-total-topics-by-subcategory-for-all-subcategories-please/235296/6 "2022-08-06T11:58:04Z")

</div>

Disregard that last comment.  
I see now how it’s done.  
Thank-you.  
That’ll help.

---

<div class="post-metadata">

**Author:** ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)\
**Post date:** [January 18, 2023, 10:16am UTC](https://meta.discourse.org/t/how-do-i-get-a-report-of-total-topics-by-subcategory-for-all-subcategories-please/235296/7 "2023-01-18T10:16:50Z")

</div>

Closed on January 18, 2023, 10:16am UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
