//Table model
id parent name
1 0 Nokia
2 0 Samsung
3 1 N70
4 1 N97
5 2 Galaxy S3
//Table image
id name
1 n70.png
2 n97.png
3 galaxys3_1.png
4 galaxys3_2.png
5 galaxys3_3.png
//Table image_to_model
id model_id image_id
1 3 1
2 4 2
3 2 3
4 2 4
5 2 5
SELECT mod.id, mod.name,GROUP_CONCAT(img.name) FROM `model` AS mod
LEFT JOIN `image_to_model` AS mod_img ON mod_img.image_id = mod.id
GROUP BY mod.id
如何产生这种格式:
1 Nokia | N70,N97 | n70.png,n97.png
2 Samsung |Galaxy S3 | galaxys3_1.png,galaxys3_2.png,galaxys3_3.png