Learn more about MySQL GROUP_CONCAT Functions

Source: Internet
Author: User

MySQL GROUP_CONCAT is a very important function. MySQL GROUP_CONCAT is added to MySQL 4.1. the syntax of this function is described in detail below.

MySQL GROUP_CONCAT (expr)
The complete syntax is as follows: GROUP_CONCAT ([DISTINCT] expr [, expr...]
[Order by {unsigned_integer | col_name | formula} [ASC | DESC] [, col...]
[SEPARATOR str_val])

The MySQL GROUP_CONCAT function is added to MySQL 4.1. The function returns a string consisting of values in the group: mysql> SELECT student_name,
-> GROUP_CONCAT (test_score)
-> FROM student
-> Group by student_name;
Or
Mysql> SELECT student_name,
-> GROUP_CONCAT (DISTINCT test_score
-> Order by test_score desc separator "")
-> FROM student
-> Group by student_name;

In MySQL, you can get the link value of a combination of expressions. You can use DISTINCT to exclude duplicate values. If you want to sort the values in the result,
You can use the order by clause. To sort in reverse ORDER, you can add a DESC (descending) keyword to the column name used for sorting in the order by clause.
. The default value is ascending, which can be explicitly specified by the ASC keyword.
A separator is a string value that is inserted into the result value. The default value is a comma (",").
You can completely remove this SEPARATOR by specifying the SEPARATOR.
In your configuration, use the variable group_concat_max_len to set a maximum length.
Run the following syntax: SET [SESSION | GLOBAL] group_concat_max_len = unsigned_integer;

If the maximum length is set, the result value is cut to this maximum length.
The GROUP_CONCAT () function is an enhanced basic LIST () function supported by Sybase SQL Anywhere.
If there is only one column and no other options are specified, GROUP_CONCAT () is a LIST () function with great limitations on backward compatibility.
LIST () has a default sorting order.

If the characters in the group are too long, you can set system parameters.

SET @ global. group_concat_max_len = 40000;

SQL date functions

Provides you with an in-depth understanding of the MYSQL Cast function.

Learn more about mysql CONCAT () Functions

How to view the three MySQL character sets

How to modify the default Character Set of 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.