sql server - SQL: Selecting parents and their children -
I'm sure this is a normal query, but I'm not sure how this is the best phrase.
I have two tables:
question {id, text ...} answer {id, question, text ...}
To get a list of questions and their answers so that the results can be displayed as: - Question A
- The first answer to Question A.
- The second answer to Question A.
- The third answer to Question A.
- Question B
- The first answer to question B ... etc
There are some selection criteria on the question table.
A very inefficient method will be to select all the relevant questions, then select all the answers for each. Another disabled method would be to use a left OUTER.
What is the most effective, easy way to get questions and answers? Can this be done in a question?
For MySQL (not MSSQL) such a thing will work; Answer in answer q.quiestionid = q.id GROUP by q.id, a.id command q.id
SELECT q.text, a.text questions
Let me know that you have a queue.
Comments
Post a Comment