Note that there are some explanatory texts on larger screens.

plurals
  1. POA value from a combination of values - Database design
    primarykey
    data
    text
    <p>I have a survey web application. The survey can have a multiple choice question. An answer to a multiple choice question can be dependent on other questions' answer.</p> <p>Example:</p> <pre><code>Question 1 has choices: HP, Acer, Samsung, Lenovo Question 2 has choices: Android, Ubuntu, iOS, Windows Question 3 has choices: Ubuntu, OS X, Windows Question 4 has choices: Adidas, Nike, Puma </code></pre> <p>Say Question 4 depends on the combination of answers from Questions 1, 2 and 3.</p> <p>Example 1:</p> <blockquote> <p>If a person answers: Question 1 = "HP", Question 2 = "Ubuntu", Question 3 = "OS X"; Question 4 is automatically set to "Puma"</p> </blockquote> <p>Example 2:</p> <blockquote> <p>If a person answers: Question 1 = "Acer", Question 2 = "Ubuntu", Question 3 = "Ubuntu"; Question 4 is automatically set to "Adidas"</p> </blockquote> <p>*Both examples have the same logic.</p> <p>Generally, some survey questions' answer can be dependent on some other survey questions' answer.</p> <p>How do you design/model a database for that purpose?</p> <p>This is the initial table relationship I've created (feel free to modify it): </p> <pre><code>Users: user_id Questions: question_id Choices: choice_id, question_id Answers: answer_id, user_id, question_id </code></pre> <p>Additional information:</p> <p>The admin user interface process I'm thinking of doing is:</p> <pre><code>1. The admin creates several independent questions (questions which have answers independent of other questions' answer) 2. The admin creates a dependent question, selects one or many questions which he created earlier, selects a combination of answers from those question (just like in examples 1 and 2 above) and then sets an answer for the dependent question based on those combination of answers. ... The admin proceeds creating several more questions. </code></pre> <p>Edit:</p> <p>Thanks for your idea @MahmoudGamal. I created something that is based on your design:</p> <pre><code> Combinations table ID question_id # the dependent question's id choice_id # the automatic answer based on the combination of other answers Answer Combinations table ID combination_id question_id # the question that is depended upon by the dependent question choice_id # the choice that will be used for the combination </code></pre> <p>So I can have several combinations for one question. Example: If I want Question 4 to accept several combinations. One combination has different answer.</p> <pre><code> Answer Combinations table ID combination_id question_id choice_id 1 1 1 1 2 1 2 2 3 1 3 3 4 2 1 2 5 2 2 2 6 2 3 1 </code></pre> <p>And the Combinations table would have</p> <pre><code> Combinations table ID question_id choice_id 1 4 4 2 4 3 </code></pre> <p>Looks pretty neat to me. What do you think?</p> <p>PS: Forgive me but I'm new to Stack Overflow and I'm still finding my way around.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload