My goal is a simple polling system where users can create a poll question, provide the poll with a set of options(answers) and vote on each poll. I’ll provide a simple set of fields I need to collect. Then, I’ll provide my solution. Could you tell me if my solution is acceptable?
Fields required: questionText, date, (poster)userId, options(answers), response, (responder)userID, responseDate
My curent solution:
Table: Polls
Fields: questionID, questionText, date, userID
Table: Options
Fields: optionID, optionText, questionID
Table: Respnoses
Fields: responseID, optionID, userID, responseDate
So to find if a user has responded to a specific poll, I would have to query like this:
SELECT responseID FROM Responses
WHERE userID = [user's id] AND optionID IN(
Select optionID FROM Options
WHERE questionID = [specific questionID])
Does that query make sense too?
Thanks in advance.
This model looks fine to me, as does the query. I’m a fan of JOINs, so I would have structured your select query more like this (not a recommendation, just a clarifying alternative):
My only thought is that, depending on your needs and how auditable you’ll want this system to be, you may want extra fields such as timestamps on the Options and Polls tables. (A “date_edited” versus “date_created”? In low-stakes contexts this may not be needed.)