【发布时间】:2020-01-01 15:53:30
【问题描述】:
我的架构:
id:int | post_hash:str | post_body: str | is_op: tinyint(1) | parent_id:int
1 | 'dddba11f43d90117b01' | 'test post' | 1 | Null
2 | Null | 'test reply'| 0 | 1
这是用于存储论坛帖子和回复。如何选择post_hash 及其由parent_id 指定的所有子帖子?为了澄清,这个想法是这样的:
SELECT p.id FROM posts p WHERE post_hash = ? or parent_id = p.id
其中p.id 是选择的结果。它是自引用的,因此需要子查询或连接,但我不确定如何处理。
【问题讨论】:
-
请edit 你的问题包含一个更大的例子,说明你想从表格中读取什么。将几个示例行添加到您的表中,并从该表中写入您想要的结果集。有关 SQL 相关问题,请参阅meta.stackoverflow.com/questions/333952/…。