tags:

views:

107

answers:

2

Some of my combined values have a comma in the textfield, is there a way I can specify the character with which to be concatenated by, instead of a comma?

+1  A: 

In the mysql documentation you can find the full syntax

GROUP_CONCAT([DISTINCT] expr [,expr ...]
         [ORDER BY {unsigned_integer | col_name | expr}
             [ASC | DESC] [,col_name ...]]
         [SEPARATOR str_val])

and the following example for GROUP_CONCAT

GROUP_CONCAT(DISTINCT test_score ORDER BY test_score DESC SEPARATOR ' ')
bjelli
A: 

This page explains this lucidly.

GROUP_CONCAT() function is used to concatenate column values into a single string. It is very useful if you would otherwise perform a lookup of many row and then concatenate them on the client end.

For example if you query:

mysql> SELECT Language FROM CountryLanguage WHERE CountryCode = 'THA';

It outputs:

Language
Chinese
Khmer
Kuy
Lao

To concatenate the values into a single string, you query:

mysql> SELECT GROUP_CONCAT(Language) As Languages FROM CountryLanguage WHERE CountryCode = 'THA';

Then the output will be:

Languages
Chinese, Khmer, Kuy, Lao

You can also use some format of GROUP_CONCAT(). Like

  • SELECT GROUP_CONCAT( Language SEPARATOR ‘-’ )… It will use ‘-’ instead of ‘,’
  • SELECT GROUP_CONCAT( Language ORDER BY Language DESC )… To change the order and shorting output.

    thing to remember:

    GROUP_CONCAT() ignores NULL values.

Saeros