MySQL GROUP_CONCAT() maximum length

MySQL SELECT

In MySql, GROUP_CONCAT() is used to convert multiple rows into a single string. However, the maximum length of the result of this function is 1024 characters.

So, You should first check the character length that GROUP_CONCAT supports in your mysql instance using below code:

SHOW VARIABLES LIKE '%group_concat%';

And You see that default character length GROUP_CONCAT supports : 1024

Read Also: SQl MATCH AGAINST find results with only more than 3 characters in the result

If 1024 character length is fine for you requirement then there is nothing to worry. But if not, you have to modify the GROUP_CONCAT character length as per your requirement as below:

SET SESSION group_concat_max_len = 1000000;

This a temporary session-scope setting. This only applies to the current session and You should use it like this.

SET SESSION group_concat_max_len = 1000000;
SELECT group_concat(`field`) FROM TABLE_NAME GROUP BY `field`;

You can also do this in sharing hosting, but when you use an other session then you need to repeat the SET SESSION command.

Leave a Reply

Your email address will not be published. Required fields are marked *