Reputation: 2156
From this question: Stackoverflows Tags system, How To
SO considers questions and answers to be the same thing - a Post.
A question has a title, whereas a reply does not, how does SO deal with this? What would the table structure be?
How do you differentiate between a question and an answer and what would go in the title field for a answer? Can you show me what this would look like in MySQL?
Upvotes: 1
Views: 107
Reputation: 9508
In general, this is a problem of object-oriented inheritance and its mapping to relational model used by databases like MySQL (or MS SQL in case of SO).
You can find more resources about that if you search using these keywords. I'll just give you a short list of different approaches to the problem:
title
column have null
value for answers. Good for performance, no need to have too many joins, too much unused data.null
values using up space, some redundant code, though.post
and a table for each subtype questions
, answers
etc. No null
values, no redundant code, but must use SQL joins for just about anything, theoretically cleanest as it is normalized (academic world seems to love that), but for large amount of data simply useless.Which particular strategy was chosen for SO, I don't know. Maybe someone of the mods would care to answer that.
Upvotes: 4