Help with GROUP_CONCAT (Mysql)

Asked

Viewed 202 times

2

I’d like to use a grupo_concat for filename and answer but not to repeat the values of filename and answer

Follows sqlfiddle:

http://sqlfiddle.com/#! 9/f32d78/1/0

It is a question that has 2 images and 4 alternatives of A-D.

name        questionText        question    filename    answer
PT-D08-H    Texto da questão    1           2.svg       Resposta A
PT-D08-H    Texto da questão    1           3.svg       Resposta A
PT-D08-H    Texto da questão    1           2.svg       Resposta B
PT-D08-H    Texto da questão    1           3.svg       Resposta B
PT-D08-H    Texto da questão    1           2.svg       Resposta C
PT-D08-H    Texto da questão    1           3.svg       Resposta C
PT-D08-H    Texto da questão    1           2.svg       Resposta D
PT-D08-H    Texto da questão    1           3.svg       Resposta D

This is the result I’m getting, when using group_concat, how to do not repeat the values of filename and answer

    name        questionText    question         group_concat(filename)                             group_concat(answer)
    PT-D08-H    Texto da...     1                2.svg,3.svg,2.svg,3.svg,2.svg,3.svg,2.svg,3.svg Resposta A,Resposta A,Resposta B,Resposta B,Resposta C,Resposta C,Resposta D,Resposta D

1 answer

0


I decided to make two views, one for perguntas and another to respostas, then just select the two by doing Join, and using the group-concat for answer and filename, worked perfectly, follows fiddle with the solution:

http://sqlfiddle.com/#! 9/e86592/1/0

Browser other questions tagged

You are not signed in. Login or sign up in order to post.