Group_concat () usage in MySQL

Source: Internet
Author: User

Basic syntax: Group_concat ([DISTINCT] field to connect [order by sort field Asc/desc] [Separator ' delimiter '])

Initial data:

  Group by name, print money on one line, default ', ' delimited:

Select AA. ' Name ' name, Group_concat (money) money from the AA GROUP by AA. ' Name '

    

  Group by name, print money on one line, separated by '; '

Select AA. ' Name ' name, Group_concat (Money separator '; ') money from the AA GROUP by AA. ' Name '

    

  Group by name, remove redundant money, separate with '; '

Select AA. ' Name ' name, Group_concat (DISTINCT money separator '; ') money from the AA GROUP by AA. ' Name '

    

parameter setting and restriction description
1. View settings on the server

Mysql> Show variables like '%group_concat% '; +----------------------+-------+ | Variable_name        |      Value | +----------------------+-------+ | Group_concat_max_len |      1024x768  | +----------------------+-------+ 1 row in Set (0.00 sec)

The value of the above setting indicates that the default length is currently 1KB

2. Changing parameter values
Method One: Modify the parameters in the configuration file, add Group_concat_max_len = 10240
Method Two: Implemented in session, global or current session
SET GLOBAL group_concat_max_len=10240;
SET SESSION group_concat_max_len=10240;

Group_concat () usage in MySQL

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.