I’m creating a threaded message board and I’m trying to keep it simple. There’s a message table, and then a replies table that has an ‘reply_id’ field that can be null to indicate a top level response, or a value that indicates a threaded response.
I’m a bit confused on how to do a SELECT call on this type of table though?
Reply -id (every reply gets a unique id) -message_id (the message it is replying to) -reply_id (the id of the reply it may be replying to - for threading) -reply
I know this can be a complex problem, especially for performance, but I’m really just looking for the most basic solution to this.
thanks…
You’re using the naive ‘textbook’ way of storing trees, i.e. store a reference to the immediate parent. This design is called Adjacency List. There are other solutions:
See my response to ‘What is the most efficient/elegant way to parse a flat table into a tree?‘ for references and examples of the Closure Table design.