Concatenate multiple rows in single rows in MySQL

后端 未结 2 1425
傲寒
傲寒 2020-12-31 14:26

How can I concatenate all the rows in single rows when I fire SELECT query?

\"enter

2条回答
  •  星月不相逢
    2020-12-31 14:52

    You'll need GROUP_CONCAT and CONCAT mysql functions and the query should look like this:

    SELECT GROUP_CONCAT( CONCAT( id, ' ', name, ' ', city, ' ', state) SEPARATOR ' ')
    FROM students
    GROUP BY (1)
    

    Or you can use CONCAT_WS instead:

    CONCAT_WS(' ', id, name, city, state)
    

提交回复
热议问题