Bug #109614 The result of the group_concat function is different
Submitted: 13 Jan 2023 6:57 Modified: 13 Jan 2023 13:35
Reporter: yue li Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:5.7.34 OS:Linux
Assigned to: CPU Architecture:Any
Tags: GROUP_CONCAT multibyte utf8

[13 Jan 2023 6:57] yue li
Description:
There's a table called g:
CREATE TABLE `g` (
  `id` int(11) DEFAULT NULL,
  `a` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

insert into g values(1,11);
insert into g values(1,22);
insert into g values(1,33);
insert into g values(2,11);
insert into g values(2,22);
insert into g values(2,33);
insert into g values(2,44);
insert into g values(3,11);
insert into g values(3,22);
insert into g values(3,33);
insert into g values(3,44);
insert into g values(4,11);
insert into g values(4,22);
insert into g values(4,33);
insert into g values(5,11);
insert into g values(5,22);
insert into g values(5,33);
insert into g values(6,11);
insert into g values(6,22);
insert into g values(6,33);
insert into g values(6,44);
insert into g values(7,11);
insert into g values(7,22);
insert into g values(7,33);
insert into g values(8,11);
insert into g values(8,22);
insert into g values(8,33);
insert into g values(8,44);
insert into g values(8,55);
insert into g values(9,11);
insert into g values(9,22);
insert into g values(9,33);
insert into g values(10,11);
insert into g values(10,22);
insert into g values(10,33);
insert into g values(10,44);

Execute the following statement:
mysql> select id,group_concat(a)  from (select * from g where id=3 order by id,a ) t group by id;
+------+-----------------+
| id   | group_concat(a) |
+------+-----------------+
|    3 | 11,22,33,44     |
+------+-----------------+

mysql> select id,group_concat(a)  from (select * from g order by id,a ) t group by id;
+------+-----------------+
| id   | group_concat(a) |
+------+-----------------+
|    1 | 11,22,33        |
|    2 | 11,22,33,44     |
|    3 | 44,33,22,11     |
|    4 | 11,22,33        |
|    5 | 11,22,33        |
|    6 | 44,33,22,11     |
|    7 | 11,22,33        |
|    8 | 55,44,33,22,11  |
|    9 | 11,22,33        |
|   10 | 11,22,33,44     |
+------+-----------------+
Why do two statements with id=3 return different results?

How to repeat:
Create the above test tables and data to replicate.
[13 Jan 2023 13:35] MySQL Verification Team
Hi Mr. li,

Thank you for for your bug report.

The answer to your question is very simple.

When ORDER BY is not specified in GROUP_CONCAT(), MySQL server can sort values in any order that it desires.

Not a bug.