Hello, i am trying to get the multiple categories on topics, example 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,
Hi Josia, welcome!
I can’t access your link, or log in. Maybe you could provide a screenshot instead?
Here as you can see there is a category and a sub-category i want to be able to see them both.
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:
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
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.