I have 2 table in the database: mainTable and classificationTable:
mainTable:
id | classification_id | name
---------------------------------------
1 | 1 | Name1
2 | 2,3,4 | Name2
3 | 1,4 | Name3
4 | 4 | Name4
classificationTable:
classification_id | class_name
---------------------------------------
1 | Class Name1
2 | Class Name2
3 | Class Name3
4 | Class Name4
I want to get a select for example for row with ID 3 from mainTable like:
id = 3
class_name = Class Name1, Class Name4
Name = Name3
I try this select, but this return only first elemnt from array (fore exempla for row with ID 3, this return only Class Name1)
SELECT i.*,
(SELECT GROUP_CONCAT(cl.class_name) FROM classificationTable as cl WHERE cl.classification_id IN(i.classification_id)) as class_name
FROM mainTable as i;
Help PLZ.