I have the following database design:
Employee Table: EmployeeID, Name, OrgCode
Department Table: OrgCode, DepartName
CompleteSurvey Table: ID, RespondantID, QuestionsAnswersID
Questions Table: QuestionID, Question
Answers Table: AnswerID, Answer
QuestionsAnswers Table: ID, QuestionID, AnswerID
Each question has different multiple choices. Besides that, I am thinking to add sub-questions under the question. Most of
the questions have the same choices such as (Agree, Disagree). I want to write the query that shows the question including
its sub-questions with all of its choices and the number of participants in each choice even if it is zero.
I am not sure if the Questions Table will help me in inserting sub-questions under any question. Is that design applicable? What do you recommend?
In your current Question table, you can’t have sub questions. You may try having an ID representing sub questions (like Question has ID 2, and Then sub question against that has ID 2A or something like that), but this design may fail and it depends on your computation of ID, also you can’t be sure of level of sub questions.
A better approach would be to have Parent-Child Dimension for self referencing relation. You may have:
where ParentID is the ID of some question. If it is null then the question is not the sub question of any question. You may also see Employee-Manager Relationship for recursive relationships, This may help you to better understand your problem