next query
SELECT answerid, answer_question_id, answer_isright,
row_number() over (partition by answer_question_id order by newid()) as rnum
from answers
will return you your answer table with extra column to represent what column that answer goes to. "order by newid()" is not part of a standard and is different for every database vendor.
answerId .... rnum
1 1
2 3
3 2
4 3
5 1
6 2
(rnums would be different for every execution)
then you use this query to move answers to different columns based on rnum
select answerid, ..., case when rnum = 1 then answertxt else null end co1, ...
this will move your text like this:
answerId .... rnum ... col1, col2 col3
1 1 text1 null null
2 3 null null text2
3 2 null text3 null
4 3 null null text4
5 1 text5 null null
6 2 null text6 null
then you need to group them:
select answer_question_id, .., max(col1), max(col2), max(col3) from prev_query
group by answer_question_id, ...
then you join with a questions to add question text