如何在不使用循环的情况下将多行连接成单个文本字符串?

时间:2015-07-23 05:20:25

标签: mysql sql phpmyadmin

假设我有一张包含以下数据的表:

ClientID    ClientName
3           saurabh Malhotra
4           patel Mon
6           Sajith raju
7           Vipin parmar
8           Monoj trivedi

我们需要连接ClientName列,如下所示:

saurabh Malhotra,patelMon,Sajith raju,Vipin parmar,Monoj trivedi

2 个答案:

答案 0 :(得分:1)

尝试此查询

select 
     group_concat(ClientName  separator ',') as ClientName 
from (select 1 as tempcol,
           ClientName 
     from tablename)tbl
group by tempcol

答案 1 :(得分:1)

试试这个:)

SELECT GROUP_CONCAT(ClientName) FROM Your_table_name

MySQL : Multiple row as comma separated single row