I’m sure this is a common query but I’m not certain how to phrase it best.
I have two tables:
Questions { Id, Text... }
Answers { Id, QuestionId, Text...}
I would like to retrieve a list of Questions and their Answers, so that the results can be displayed like this:
- Question A
- 1st answer to question A
- 2nd answer to question A
- 3rd answer to question A
- Question B
- 1st answer to question B
… etc
- 1st answer to question B
Assume that there is some selection criteria on the Question table.
A very inefficient method would be to select all the relevant questions, then for each select all the answers. Another inefficient method would be to use a LEFT OUTER JOIN.
What’s the most efficient, simplest way of getting the questions and answers? Can it be done in one query?
For MySQL (not MSSQL) Something like this would work;
Let me know if you have any q’s.