mysqlsqlrdbmsrdbms-agnostic

'questions' and 'answers' with multiple answers


This question is related to this post: SQL design for survey with answers of different data types

I have a survey app where most questions have a set of answers that are 1-5. Now we have to do questions that could have a variety of different answer types -- numeric, date, string, etc. Thanks to suggestions from stack, I went with a string column to store answers. Some questions are multiple choice, so along with the table 'questions', I have a table 'answers' which has the set of possible answers for a question.

Now: how should I store answers for a question that is "pick all that apply"? Should I make a child table that is "chosen_answers" or something like that? Or should the answers table have a 'chosen' column that indicates that a respondent chose that answer?


Solution

  • a possible solution is a UsersAnswers table with 4 columns: primary key, user's id, question's id, and answer's id

    with multiple entries for any questions where more than one answer can be selected