# Multiple Categories on Topics

**URL:** https://meta.discourse.org/t/multiple-categories-on-topics/283250
**Category:** Data & reporting
**Tags:** sql-query
**Created:** [October 24, 2023, 11:17am UTC](https://meta.discourse.org/t/multiple-categories-on-topics/283250 "2023-10-24T11:17:00Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![joc](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/joc/32/332857_2.png) [@joc](https://meta.discourse.org/u/joc)
#### Post date: [October 24, 2023, 11:17am UTC](https://meta.discourse.org/t/multiple-categories-on-topics/283250/1 "2023-10-24T11:17:00Z")

</div>

Hello, i am trying to get the multiple categories on topics, example [https://www.waze.com/discuss/t/trouble-installing/13068](https://www.waze.com/discuss/t/trouble-installing/13068)  
when i try going into the topics table i only see 1 of the categories in this dataset, i would like to know how possible it’s to get both categories related to this topic.

Thank you in advance,

---

<div class="post-metadata">

### Author: ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)
#### Post date: [October 24, 2023, 2:59pm UTC](https://meta.discourse.org/t/multiple-categories-on-topics/283250/2 "2023-10-24T14:59:17Z")

</div>

Hi Josia, welcome! 👋

I can’t access your link, or log in. Maybe you could provide a screenshot instead?

---

<div class="post-metadata">

### Author: ![joc](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/joc/32/332857_2.png) [@joc](https://meta.discourse.org/u/joc)
#### Post date: [October 24, 2023, 3:32pm UTC](https://meta.discourse.org/t/multiple-categories-on-topics/283250/3 "2023-10-24T15:32:44Z")

</div>

![A7UCov5SHng9rKf](https://global.discourse-cdn.com/meta/original/4X/4/9/a/49ad74ee6f94010aabc38f6bcec86e12efc7d262.png)  
Here as you can see there is a category and a sub-category i want to be able to see them both.

---

<div class="post-metadata">

### Author: ![simonk](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simonk/32/247950_2.png) [@simonk](https://meta.discourse.org/u/simonk)
#### Post date: [October 24, 2023, 4:31pm UTC](https://meta.discourse.org/t/multiple-categories-on-topics/283250/4 "2023-10-24T16:31:55Z")

</div>

The `category` table contains a `parent_category_id` containing the ID of the parent category, or `NULL` if the category doesn’t have a parent. To get both categories, you probably want to `LEFT JOIN` to the `category` table a second time, something like this:

```sql
SELECT
    t.id as topic_id,
    c.id as category_id,
    pc.id as parent_category_id
FROM topics t
INNER JOIN categories c ON t.category_id = c.id
LEFT JOIN categories pc ON c.parent_category_id = pc.id
LIMIT 20

```

---

<div class="post-metadata">

### Author: ![joc](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/joc/32/332857_2.png) [@joc](https://meta.discourse.org/u/joc)
#### Post date: [October 24, 2023, 6:16pm UTC](https://meta.discourse.org/t/multiple-categories-on-topics/283250/5 "2023-10-24T18:16:28Z")

</div>

Thank you for the 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: [November 23, 2023, 6:17pm UTC](https://meta.discourse.org/t/multiple-categories-on-topics/283250/6 "2023-11-23T18:17:26Z")

</div>

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