您好,我正在尝试获取主题的多个类别,例如 https://www.waze.com/discuss/t/trouble-installing/13068
当我尝试进入 topics 表时,我只看到此数据集中 1 个类别,我想知道是否有可能获取与此主题相关的两个类别。
提前致谢,
您好,我正在尝试获取主题的多个类别,例如 https://www.waze.com/discuss/t/trouble-installing/13068
当我尝试进入 topics 表时,我只看到此数据集中 1 个类别,我想知道是否有可能获取与此主题相关的两个类别。
提前致谢,
嗨 Josia,欢迎! ![]()
我无法访问您的链接或登录。也许您可以提供截图?
category 表包含一个 parent_category_id,其中包含父类别的 ID,如果没有父类别则为 NULL。要同时获取两个类别,您可能需要将 category 表 LEFT JOIN 第二次,如下所示:
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
谢谢你的帮助。
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.