group_concat

description

Syntax

VARCHAR GROUP_CONCAT(VARCHAR str[, VARCHAR sep])

This function is an aggregation function similar to sum (), and group_concat links multiple rows of results in the result set to a string. The second parameter, sep, is a connection symbol between strings, which can be omitted. This function usually needs to be used with group by statements.

example

  1. mysql> select value from test;
  2. +-------+
  3. | value |
  4. +-------+
  5. | a |
  6. | b |
  7. | c |
  8. +-------+
  9. mysql> select GROUP_CONCAT(value) from test;
  10. +-----------------------+
  11. | GROUP_CONCAT(`value`) |
  12. +-----------------------+
  13. | a, b, c |
  14. +-----------------------+
  15. mysql> select GROUP_CONCAT(value, " ") from test;
  16. +----------------------------+
  17. | GROUP_CONCAT(`value`, ' ') |
  18. +----------------------------+
  19. | a b c |
  20. +----------------------------+
  21. mysql> select GROUP_CONCAT(value, NULL) from test;
  22. +----------------------------+
  23. | GROUP_CONCAT(`value`, NULL)|
  24. +----------------------------+
  25. | NULL |
  26. +----------------------------+

keyword

GROUP_CONCAT,GROUP,CONCAT