Hi Everyone:
The Situation:
I am working on a web-based questionnaire project. I have two tables: WizardQuestions and WizardChoices -- WizardQuestions stores the questions themselves, while the WizardChoices stores the possible answers associated with each question.
Database Schema:
WizardQuestions has the following fields:
1. question_id
2. question_header
3. question_body
WizardChoices has the following fields:
1. choice_id
2. assoc_question_id (Relates to table above)
3. choice_text
The Problem:
Using one query, I need to get:
1. question_header from WizardQuestions
2. question_body from WizardQuestions
3. choice_text from WizardChoices associated with that question.
** Header and question body should be returned once **
I have tried:
The inter-select:
Select wizard_questions.question_id,
wizard_questions.question_header,
wizard_questions.question_body
FROM
wizard_questions
WHERE
wizard_questions.question_id =
(Select wizard_question_choices.choice_text from wizard_question_choices where wizard_questions.question_id = wizard_question_choices.assoc_question_id);
The JOIN:
SELECT WizardQuestions.question_header,
WizardQuestions.question_body,
WizardChoices.choice_text
FROM WizardQuestions
JOIN WizardChoices
ON WizardQuestions.question_id = WizardChoices.assoc_question_id;
I have had very little success. If I run the join statement without a GROUP BY statement, then the question_header and question_body are shown twice -- with both choice options, but if I add a GROUP BY statement, then the header and body are shown, but with one option only.
Any help would be greatly appreciated!