206

I have a query where I am using GROUP_CONCAT and a custom separator as my results may contain commas: '----'

This all works well, however it is still comma separated, so my output is:

Result A----,Result B----,Result C----

How can I make it so the output is:

Result A----Result B----Result C----

I thought this was the idea of a custom separator!

Failing that, can you escape commas in your results, so I can explode in PHP by the GROUP_CONCAT commas?

2
  • Where are the commas coming from? Are they the separators, or part of the results? That part of the question isn't clear to me. Commented Oct 7, 2011 at 19:14
  • 1
    GROUP_CONCAT(artists.artistname, '----') is my group concat line - as you can see, I have not put comma as the separator - they are not in the results but show in the output Commented Oct 7, 2011 at 19:15

3 Answers 3

466

Looks like you're missing the SEPARATOR keyword in the GROUP_CONCAT function.

GROUP_CONCAT(artists.artistname SEPARATOR '----')

The way you've written it, you're concatenating artists.artistname with the '----' string using the default comma separator.

Sign up to request clarification or add additional context in comments.

Comments

47

Query to achieve your requirment

SELECT id,GROUP_CONCAT(text SEPARATOR ' ') AS text FROM table_name group by id;

1 Comment

The requirement was to use ---- as a separator.
0

Or, if you are doing a split - join:

GROUP_CONCAT(split(thing, " "), '----') AS thing_name,

You may want to inclue WITHIN RECORD, like this:

GROUP_CONCAT(split(thing, " "), '----') WITHIN RECORD AS thing_name,

from BigQuery API page

1 Comment

the question is tagged MySQL, not BigQuery

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.