GROUP_CONCAT() row count when grouping by a text field

孤人 提交于 2019-12-01 03:39:47

You have to change the max_sort_length to higher number session wise or globally as per your need. By default its value is 1024 bytes and your string contains 1170 bytes data. By increasing the size it will give two rows for GROUP_CONCAT.

Check this link max_sort_length

SELECT `text` FROM `table` GROUP BY `text`;

SET SESSION max_sort_length = 2000;
SELECT GROUP_CONCAT(`id` SEPARATOR ', ') AS ids FROM `table` GROUP BY `text`;

Check the SQL FIDDLE DEMO

EDIT: BLOB and TEXT values can't reliably be used in GROUP BY, ORDER BY or DISTINCT. Only the first max_sort_length bytes are used when comparing BLOB values in these cases. The default value of max_sort_length is 1024 and can be changed at server start-up time or at run time.

It seems you're running into MySQL's default GROUP_CONCAT_MAX_LEN. Your string has a length of 1178, which is definitely over the default value of 1024. That means, if the values differ by something later than the 1024, MySQL will simply ignore it, because the first 1024 characters are exactly identical. This is a limit on GROUP_CONCAT's behavior, not on GROUP.

You can make this bigger in the my.cnf file for MySQL.

See here for some more details:

http://www.coderanch.com/t/422632/JDBC/databases/increase-group-concat-max-len

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!