Specific usage of MySQLGROUP_CONCAT

Source: Internet
Author: User

In the following article, the Han nationality wants to talk about the specific use scheme of MySQLGROUP_CONCAT. In order to describe the specific operation steps of MySQLGROUP_CONCAT in more detail, we also give an example to better explain it, the following describes the specific solution.

 
 
  1. sql: case when, distinct, group by, group_concat  

Optimization of MySQL for large WEB Applications

My base64

Recommendation circle: Database circle

For more information, we recommend that GROUP_CONCAT accumulate the values of a field based on the specified characters. The default Delimiter is comma, and the length of characters that can be accumulated is 1024 bytes. You can modify these parameters.

1. A simple example

 
 
  1. select group_concat(f_a) from t_one group by f_b; 

Query by group by f_ B and accumulate f_a in each group.

2. Modify the default delimiter

 
 
  1. select group_concat(f_a separator '_') from t_one group by f_b; 

Separator is a keyword followed by the characters to be separated

3. Sorting

 
 
  1. select group_concat(f_a order by f_a separator '_') from t_one group by f_b; 

4. Modify the default character size

1) Add the following in the MySQL configuration file:

Group_concat_max_len = 102400 # maximum length you want

2). You can simply execute the statement and set the scope of the action.

 
 
  1. SET GLOBAL group_concat_max_len=102400;  
  2. SET SESSION group_concat_max_len=102400; 

5. Use with concat

Group_concat by default, a large BLOB Object is returned. You can use concat to return a string. You can also add other data in the returned content.



The above content is the description of MySQLGROUP_CONCAT, and I hope it will help you in this regard.

Related Article

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.