Mysql Group_concat Usage Precautions

Source: Internet
Author: User

The Group_concat function returns a string result that is composed of concatenated values in the grouping, often used with group by.

If you need a custom delimiter, you can use SEPARATOR.

Example:

SELECT group_concat (ID) IDs from sys_oem_resources WHERE The PID is not a NULL GROUP by PID;

SELECT group_concat (id SEPARATOR ' * ') IDs from Sys_oem_resources WHERE pid are not NULL GROUP by PID;

Note the example:

Do not use Group_concat, perhaps you now use the Group_concat get the result is hidden bug.

The results of the Group_concat are limited by the Group_concat_max_len variable.

The default Group_concat_max_len = 1024, which means that the length of the string exceeds 1024 bytes is truncated.

See the default length of Group_concat by command "show variables like ' Group_concat_max_len '":

Mysql> Show variables like ' Group_concat_max_len ';
+----------------------+-------+
| variable_name | Value |
+----------------------+-------+
| Group_concat_max_len | 1024 |
+----------------------+-------+
1 row in Set

Add configuration to MySQL config file: group_concat_max_len = 1 (-1 for maximum or set length according to actual requirement), after configuration, restart MySQL service, see below:

Mysql> Show variables like ' Group_concat_max_len ';
+----------------------+------------+
| variable_name | Value |
+----------------------+------------+
| Group_concat_max_len | 4294967295 |
+----------------------+------------+
1 row in Set

Mysql Group_concat Usage Precautions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.