根据列连接行的字符串

时间:2013-08-01 04:37:01

标签: mysql

我哈瓦表

MsgID    Msg              value
ms001    I am here.       ----
ms001    Wher are you     dsdad
ms002    who r u          gfsdfdf
ms002    where is this    dadad
ms002    I am goin        adadad

这可以通过MySQL查询得到这样的结果

ms001    I am here. Wher are you
ms002    who r u wher is this I am goin  

1 个答案:

答案 0 :(得分:6)

<强> Read about group_concat

SELECT MsgID , GROUP_CONCAT(Msg SEPARATOR ' ') AS Msg
FROM table1
GROUP BY MsgID;

<强> SQL Fiddle