mysql GROUP_CONCAT
table 1:
+----+---------+ | id | content | +----+---------+ | 1 | num1 | | 2 | num2 | | 3 | num3 | | 4 | num4 | | 5 | num5 | +----+---------+
table 2:
+----------+---------+-----------+ | appln_id | pers_id | pers_name | +----------+---------+-----------+ | 1 | 1 | Jack | | 2 | 2 | Mill | | 2 | 3 | Zach | | 3 | 4 | Wong | | 3 | 5 | Lee | | 3 | 6 | Bill | | 4 | 7 | Pill | | 5 | 8 | Fee | | 5 | 9 | Grr | +----------+---------+-----------+
SQL query:
select a.id, a.content, GROUP_CONCAT(p.pers_name) from appln as a left join persons as p on a.id= p.appln_id group by a.id;
result:
+----+---------+---------------------------+ | id | content | GROUP_CONCAT(p.pers_name) | +----+---------+---------------------------+ | 1 | num1 | Jack | | 2 | num2 | Mill,Zach | | 3 | num3 | Wong,Lee,Bill | | 4 | num4 | Pill | | 5 | num5 | Fee,Grr | +----+---------+---------------------------+