如何使用嵌套结构进行查询?

时间:2022-09-28 14:32:11

I have the following table structure: table forum

我有以下表结构:表论坛

forum_id | parent_id

where parent_id - any nesting depth table thread

其中parent_id - 任何嵌套深度表线程

thread_id | forum_id

where forum_id -foreign key table forum table message

其中forum_id -foreign关键表论坛表消息

message_id | thread_id

where thread_id-foreign key table thread How can I count the number of messages to a particular forum? (сonsidering that there may be nested forums) sorry for my english, thanks.

thread_id-foreign key table thread哪里可以计算到特定论坛的消息数量? (可能有嵌套论坛)对不起我的英文,谢谢。

1 个解决方案

#1


0  

At the moment MySQL doesn't seem to be supporting recursive SQL queries. Although, you might consider changing your data structure to achieve the goal easier.

目前MySQL似乎不支持递归SQL查询。虽然,您可以考虑更改数据结构以更轻松地实现目标。

Take a look, for example, at this question: What is the most efficient/elegant way to parse a flat table into a tree?

例如,看看这个问题:将平台解析成树的最有效/优雅的方法是什么?

#1


0  

At the moment MySQL doesn't seem to be supporting recursive SQL queries. Although, you might consider changing your data structure to achieve the goal easier.

目前MySQL似乎不支持递归SQL查询。虽然,您可以考虑更改数据结构以更轻松地实现目标。

Take a look, for example, at this question: What is the most efficient/elegant way to parse a flat table into a tree?

例如,看看这个问题:将平台解析成树的最有效/优雅的方法是什么?