I am trying to randomly select N amount of rows from 2 tables. My first table looks like this:
q_id | question_text
-----------------
1 | What am I doing?
2 | Who are you?
3 | Hmm?
The table I'm joining to it looks like this:
a_id | q_id | answer_text
-------------------------
1 | 1 | Nothing
2 | 1 | Something
3 | 2 | Mike
4 | 2 | Steve
5 | 2 | Jon
6 | 3 | Yup
7 | 3 | Nope
I want to output a random question with their answers. So if I have 50 rows, I could select, for example, the top 3 and it would output 3 random questions with however many answers there are.
This is the query that I've been working but when I use the TOP(2), it only grabs the top 2 answers and not top 2 questions:
Query:
SELECT TOP(2) q.q_id, q.question_text, a.answer_text
FROM question q
INNER JOIN answers a ON q.q_id= a.q_id
Current results:
2 | Who are you? | Mike, Steve
Expected results:
1 | What am I doing? | Nothing, Something
3 | Who are you? | Mike, Steve, Jon