I have learned that SO has put questions and answers in the same table. They say that a question will not have a parent id and answers will have parent IDs. Why is it better to do it this way instead of putting questions and answers in separate tables?
Share
Several reasons:
The best way to look at this problem is to run a particular model through some use cases.
For example: list all posts by a user in some order (votes, date, etc). Across two tables you end up doing some kind of UNION, which is not really undesirable. If they’re stored in the same table it’s much easier. If you just want to limit it to questions or answers then the same table is still easy as it’s just an extra criteria (eg WHERE parentID IS NULL for questions).