My schema:
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
This is to store forum posts and replies. How can I select post_hash
and all its child posts specified by parent_id
? To clarify, the idea is something like:
SELECT p.id FROM posts p WHERE post_hash = ? or parent_id = p.id
where p.id
is the result of the select. It's self-referential so a subquery or join will be needed but I'm not sure how to go about this one.