Concatenate multiple rows in single rows in MySQL

后端 未结 2 1413
傲寒
傲寒 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)
    
    0 讨论(0)
  • 2020-12-31 15:05

    Use conbination of group_concat and concat functions

     SELECT group_concat( concat( id, " ",name," ",city," ",state," " ) SEPARATOR ' ')
     FROM tablename
    
    0 讨论(0)
提交回复
热议问题