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. +-------+

10. mysql> select GROUP_CONCAT(value) from test;
11. +-----------------------+
12. | GROUP_CONCAT(`value`) |
13. +-----------------------+
14. | a, b, c               |
15. +-----------------------+

17. mysql> select GROUP_CONCAT(value, " ") from test;
18. +----------------------------+
19. | GROUP_CONCAT(`value`, ' ') |
20. +----------------------------+
21. | a b c                      |
22. +----------------------------+

24. mysql> select GROUP_CONCAT(value, NULL) from test;
25. +----------------------------+
26. | GROUP_CONCAT(`value`, NULL)|
27. +----------------------------+
28. | NULL                       |
29. +----------------------------+

keyword

GROUP_CONCAT,GROUP,CONCAT