Nike Yulistia Angreni Nike Yulistia Angreni - 5 months ago 10
MySQL Question

How to show value that has column with multiple value in another table in MySQL

I have A table:


enter image description here



Then B table:


enter image description here



Last one, C table:


enter image description here


I need to show them to be like this:

performance_id | quiz_id
________________________
22 | 65
23 | null
24 | 43
25 | null


I tried join but it show wrong result. It not show quiz id. I tried this:

SELECT A.performance_id, C.quiz_id
FROM A
LEFT JOIN B ON A.performance_id=B.performance_id
LEFT JOIN C ON B.phc_id = C.phc_id
group BY A.performance_id;


result:

enter image description here

Help me,thanks

Answer

Use group_concat:

SELECT A.performance_id, group_concat(C.quiz_id) 
FROM A 
LEFT JOIN B ON A.performance_id=B.performance_id 
LEFT JOIN C ON B.phc_id = C.phc_id 
group BY A.performance_id;

Because you get more than one quiz_id

Comments