I'm writing a basic forum system for my site using MySQL. I need a way to track not only posts, but responses TO the posts. Since each post can only have ONE parent, but can ultimately have MULTIPLE children, I'm thinking I need two tables. The first table contains at a minimum the titles, the bodies and the parent of each post. The second table contains only a reference to PARENT posts and their corresponding CHILDREN, like so:
Posts Table
ID | PARENT | TITLE | POST
1 | | Msg 1 | Body 1
2 | | Msg 2 | Body 2
3 | | Msg 3 | Body 3
4 | 2 | Msg 4 | Body 4
5 | 1 | Msg 5 | Body 5
6 | | Msg 6 | Body 6
7 | | Msg 7 | Body 7
8 | 5 | Msg 8 | Body 8
9 | | Msg 9 | Body 9
10 | 1 | Msg 10 | Body 10
11 | 1 | Msg 11 | Body 11
12 | 2 | Msg 12 | Body 12
Children Table
ID | PARENT | CHILDREN
1 | 2 | 4
2 | 1 | 5
3 | 5 | 8
4 | 1 | 10
5 | 1 | 11
6 | 2 | 12
In this example, Message 1 has 3 children: 5, 10 & 11. Message 2 has 2 children: 4 & 12. Etc.
Armed with this information, I'm trying to find the best way to determine the children of a subset of my Posts list (Say Messages 5 thru 10)? Would a JOIN of some sort allow a single query to get the parents and any corresponding children? Or am I better served doing separate queries on each parent message to determine its children?
I'm trying to get my head around JOIN and it's confusing as heck. Sorry if this is basic stuff, but thanks in advance.