I have a table using 4.1x that has data like this:
p_id email participant_answer
2 test@test.com a
2 test@test.com b
2 test@test.com c
2 test@test.com d
2 test@test.com e
1 test@test.com a
1 test@test.com c
1 test@test.com d
1 test@test.com b
1 test@test.com d
5 test@test.com a
5 test@test.com c
5 test@test.com d
5 test@test.com b
5 test@test.com d
What I really need is this format
p_id participants_answers
1 a, b, c, d, e
2 a, b, c, d, e
5 a, c, d, b, d
Is there any way to get the values into grouping separated by comma.
You can get all values in a single row in MySQL using its GROUP_CONCAT function. Try as follow:
SELECT p_id,GROUP_CONCAT(participant_answer ORDER BY p_id SEPARATOR ',')
AS participant_answers
FROM table_name
WHERE email = 'test@test.com' GROUP BY p_id ORDER BY p_id;
For more help, you may visit
http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html