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 | +----+---------+---------------------------+
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。