1

I have these three tables for a little quiz. Each question has one correct and three wrong answers

Table Name:            Columns:
Questions                   QuestionID, QuestionText, 
                            AnswerID (this stores id of correct answer)

Answers                     AnswerID, AnswerText, QuestionID
QuestionsAnswers            QuestionID,AnswerID

This query

SELECT QuestionText, AnswerText
FROM [Questions] LEFT OUTER JOIN [Answers]
ON Questions.QuestionID=Answers.AnswerID;

gives me the following result

What is the capital of England? London
What is the capital of France?  Paris
What is the capital of USA?         Washington

I actually need to see the other three wrong answers grouped with each question as well. Kind of like

 What is the capital of England?    London
 What is the capital of England?    Berlin
 What is the capital of England?    BikiniBottom
 What is the capital of England?    Nottingham
 ... -- more results for France, USA and others follow

How can I modify my query above to get a similar result? Thanks

4 Answers 4

3

SELECT QuestionText, AnswerText FROM [Answers] LEFT OUTER JOIN [Question] ON Answers.QuestionID=Questions.QuestionID;

Sign up to request clarification or add additional context in comments.

Comments

2

From your table structure above, how about

SELECT QuestionText, AnswerText
FROM [Questions] LEFT OUTER JOIN [Answers]
ON Questions.QuestionID=Answers.QuestionID;

Note Answers.QuestionID not Answers.AnswerID

1 Comment

Thank you. All answers were good and worked, but yours came the fastest and also the last line with the note was important.Merci
2

Try this

SELECT QuestionText, AnswerText
FROM [Questions] LEFT OUTER JOIN [Answers]
ON Questions.QuestionID=Answers.QuestionID;

Comments

1

Maybe you have to join with QuestionsAnswers Try below solution

SELECT QuestionText, AnswerText
FROM [Questions] 
JOIN [QuestionsAnswers] ON QuestionsAnswers.QuestionID=QuestionsAnswers.AnswerID;
JOIN [Answers] ON QuestionsAnswers.AnswerID=Answers.AnswerID;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.