Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql group_concat not bringing entire data

Tags:

sql

mysql

I am using the following query and utilizing the group_concat function. However, at times the data in the answers column is being cut off; meaning I don't get the entire data, in the end it is just chopped off.

I suspect it might have something to do with the datatype....can it be casted to a bigger datatype? Currently the Other1 datatype is text

 select SiteName, 
case 
when group_concat(Other1) is not null 
  then  group_concat( cast(Other1 AS BLOB)) 
when group_concat(Other1) is null
  then  'No Response provided'
end
 'answers'
from disparities_community_partnerships
where QuarterId=2
group by SiteName
like image 344
Omnipresent Avatar asked Apr 05 '11 00:04

Omnipresent


People also ask

Is there a length 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.

What does Group_concat do in MySQL?

GROUP_CONCAT is a function which concatenates/merges the data from multiple rows into one field. It is a GROUP BY function which returns a string if the group contains at least 1 non-null value, if it does not, it returns a Null value.

Can we use Group_concat in SQL Server?

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.


3 Answers

http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_group-concat

The result is truncated to the maximum length that is given by the group_concat_max_len system variable, which has a default value of 1024. The value can be set higher, although the effective maximum length of the return value is constrained by the value of max_allowed_packet. The syntax to change the value of group_concat_max_len at runtime is as follows, where val is an unsigned integer

SET [GLOBAL | SESSION] group_concat_max_len = val;
like image 127
RichardTheKiwi Avatar answered Oct 29 '22 00:10

RichardTheKiwi


One more sample Example Execute like this

SET GLOBAL  group_concat_max_len = 5555555;
 select SiteName, 
case 
when group_concat(Other1) is not null 
  then  group_concat( cast(Other1 AS BLOB)) 
when group_concat(Other1) is null
  then  'No Response provided'
end
 'answers'
from disparities_community_partnerships
where QuarterId=2
group by SiteName
like image 32
Mahendra Jella Avatar answered Oct 28 '22 23:10

Mahendra Jella


Set the group_concat_max_len before your query:

SET GLOBAL  group_concat_max_len = 9999999;
like image 3
cksahu Avatar answered Oct 28 '22 22:10

cksahu