Table 1: question
id | question
----------------
1 | Name
2 | Age
3 | Gender
4 | Position
Table 2: answer
qid | ans | record
-----------------------
1 | Jay | 1
2 | 24 | 1
3 | M | 1
2 | 23 | 2
I want to come up with a join query that results in the following table:
record | question | ans
-----------------------------
1 | Name | Jay
1 | Age | 24
1 | Gender | M
1 | Position | null
2 | Name | null
2 | Age | 23
2 | Gender | null
2 | Position | null
The closest I can come up with is this join:
select a.record, q.question, a.ans
from
question q left outer join answer a
on q.id = a.qid order by a.record,q.id;
However, this query only produces this, but I want all the questions to show twice
record | question | ans
-----------------------------
1 | Name | Jay
1 | Age | 24
1 | Gender | M
1 | Position | null
2 | Age | 23