Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to quote values using group_concat

I need to use group_concat to build a list of comma separated values but I need the values to be quoted. How do I do this?

This:

425,254,431,53,513,13,1,13 

Should be converted to:

'425','254','431','53','513','13','1','13' 
like image 913
jim Avatar asked Mar 07 '10 01:03

jim


People also ask

What does Group_concat do in SQL?

The GROUP_CONCAT() function in MySQL is used to concatenate data from multiple rows into one field. This is an aggregate (GROUP BY) function which returns a String value, if the group contains at least one non-NULL value. Otherwise, it returns NULL.

Is there a limit to Group_concat?

Show activity on this post. I'm using GROUP_CONCAT() in a MySQL query to convert multiple rows into a single string. However, the maximum length of the result of this function is 1024 characters.

What is the difference between concat and Group_concat in MySQL?

The difference here is while CONCAT is used to combine values across columns, GROUP_CONCAT gives you the capability to combine values across rows. It's also important to note that both GROUP_CONCAT and CONCAT can be combined to return desired results.


1 Answers

Use:

GROUP_CONCAT(CONCAT('''', your_column, '''' )) 
like image 174
OMG Ponies Avatar answered Oct 10 '22 00:10

OMG Ponies