I've a query
SELECT t1.user,t1.answer as 'Q1',t2.answer as 'Q2'
from
(select answer,user from survey_answer where question_id=45) t1
JOIN
(select answer,user from survey_answer where question_id=46) t2
ON
t1.user=t2.user
In this the question_id
i.e. 45,46,47,48,…etc. is in hundreds
the number on join increases number of columns as q1,q2,q3… so on…
like :
________________________ user | q1 | q2 | q4 | q5 ------------------------ 1 | ok | yes| | no ------------------------ 2 | | yes| no |
Is there a way to form the query using IN(45,46,47,….) or use loop in procedure/function…
Best Answer
If you don't need a column for each answer you can use group_concat() to build a single string with all answers per user.
This is the result:
Rextester here