Reputation: 89
I have this query
SELECT IF( sort_order =1, title, NULL ) AS q1, IF( sort_order =2, title, NULL ) AS q2,
IF( sort_order =3, title, NULL ) AS q3
FROM `choice`
WHERE `question_id` =1101
that displays this result
q1 q2 q3
Pollster NULL NULL
NULL Snooper NULL
NULL NULL The Tank
Is there a way to group or order that will give me this result
q1 q2 q3
Pollster Snooper The Tank
Upvotes: 1
Views: 42
Reputation: 1269773
Yes. Just include aggregation functions:
SELECT max(IF( sort_order =1, title, NULL )) AS q1,
max(IF( sort_order =2, title, NULL )) AS q2,
max(IF( sort_order =3, title, NULL )) AS q3
FROM `choice`
WHERE `question_id` = 1101;
Upvotes: 1