group_concat MYSQL new line

后端 未结 4 1549
逝去的感伤
逝去的感伤 2020-12-06 10:00
group_concat(A,\' \',B,\' \',C) as Name,

then using this php for displaying



        
相关标签:
4条回答
  • 2020-12-06 10:32

    For MySQL (or plain text) output You could use \n as a separator:

    SELECT GROUP_CONCAT(column1 SEPARATOR '\n') FROM table1;
    

    I use this very often when I need to get many new-line-separated values in one row for other processing.

    0 讨论(0)
  • 2020-12-06 10:36

    I don't understand what do you mean by line break between X and Y, but if you need the values to be comma separated you can add any separator to the Group_Concat like that:

    group_concat(Name SEPARATOR ' ') as Name
    

    and here is some other separators you can use.

    0 讨论(0)
  • 2020-12-06 10:39

    Example

    SELECT Name, GROUP_CONCAT(city SEPARATOR '\n') AS city, nb
    FROM
    (SELECT 'A' AS Name, 'Agra' AS city, 101 AS nb
    UNION ALL
    SELECT 'B' AS Name, 'Delhi' AS city, 102 AS nb
    UNION ALL
    SELECT 'A' AS Name, 'Allahabad' AS city, 101 AS nb) AS a
    GROUP BY Name, nb;
    
    0 讨论(0)
  • 2020-12-06 10:54

    I figured it out. this is the correct way to add line break as seperator in the browser:

    group_concat(A,' ',B,' ',C separator '<br>') as Name,
    
    0 讨论(0)
提交回复
热议问题