1
drop table if exists t1, t2;
2
create table t1 (grp int, a bigint, c char(10) not null, d char(10) not null);
3
insert into t1 values (1,1,"a","a");
4
insert into t1 values (2,2,"b","a");
5
insert into t1 values (2,3,"c","b");
6
insert into t1 values (3,4,"E","a");
7
insert into t1 values (3,5,"C","b");
8
insert into t1 values (3,6,"D","b");
9
insert into t1 values (3,7,"d","d");
10
insert into t1 values (3,8,"d","d");
11
insert into t1 values (3,9,"D","c");
12
select grp,group_concat(c) from t1 group by grp;
17
explain extended select grp,group_concat(c) from t1 group by grp;
18
id select_type table type possible_keys key key_len ref rows filtered Extra
19
1 SIMPLE t1 ALL NULL NULL NULL NULL 9 100.00 Using filesort
21
Note 1003 select `test`.`t1`.`grp` AS `grp`,group_concat(`test`.`t1`.`c` separator ',') AS `group_concat(c)` from `test`.`t1` group by `test`.`t1`.`grp`
22
select grp,group_concat(a,c) from t1 group by grp;
27
select grp,group_concat("(",a,":",c,")") from t1 group by grp;
28
grp group_concat("(",a,":",c,")")
31
3 (4:E),(5:C),(6:D),(7:d),(8:d),(9:D)
32
select grp,group_concat(c separator ",") from t1 group by grp;
33
grp group_concat(c separator ",")
37
select grp,group_concat(c separator "---->") from t1 group by grp;
38
grp group_concat(c separator "---->")
41
3 E---->C---->D---->d---->d---->D
42
select grp,group_concat(c order by c) from t1 group by grp;
43
grp group_concat(c order by c)
47
select grp,group_concat(c order by c desc) from t1 group by grp;
48
grp group_concat(c order by c desc)
52
select grp,group_concat(d order by a) from t1 group by grp;
53
grp group_concat(d order by a)
57
select grp,group_concat(d order by a desc) from t1 group by grp;
58
grp group_concat(d order by a desc)
62
select grp,group_concat(a order by a,d+c-ascii(c)-a) from t1 group by grp;
63
grp group_concat(a order by a,d+c-ascii(c)-a)
67
select grp,group_concat(a order by d+c-ascii(c),a) from t1 group by grp;
68
grp group_concat(a order by d+c-ascii(c),a)
72
select grp,group_concat(c order by 1) from t1 group by grp;
73
grp group_concat(c order by 1)
77
select grp,group_concat(distinct c order by c) from t1 group by grp;
78
grp group_concat(distinct c order by c)
82
select grp,group_concat(distinct c order by c desc) from t1 group by grp;
83
grp group_concat(distinct c order by c desc)
87
explain extended select grp,group_concat(distinct c order by c desc) from t1 group by grp;
88
id select_type table type possible_keys key key_len ref rows filtered Extra
89
1 SIMPLE t1 ALL NULL NULL NULL NULL 9 100.00 Using filesort
91
Note 1003 select `test`.`t1`.`grp` AS `grp`,group_concat(distinct `test`.`t1`.`c` order by `test`.`t1`.`c` DESC separator ',') AS `group_concat(distinct c order by c desc)` from `test`.`t1` group by `test`.`t1`.`grp`
92
select grp,group_concat(c order by c separator ",") from t1 group by grp;
93
grp group_concat(c order by c separator ",")
97
select grp,group_concat(c order by c desc separator ",") from t1 group by grp;
98
grp group_concat(c order by c desc separator ",")
102
select grp,group_concat(distinct c order by c separator ",") from t1 group by grp;
103
grp group_concat(distinct c order by c separator ",")
107
explain extended select grp,group_concat(distinct c order by c separator ",") from t1 group by grp;
108
id select_type table type possible_keys key key_len ref rows filtered Extra
109
1 SIMPLE t1 ALL NULL NULL NULL NULL 9 100.00 Using filesort
111
Note 1003 select `test`.`t1`.`grp` AS `grp`,group_concat(distinct `test`.`t1`.`c` order by `test`.`t1`.`c` ASC separator ',') AS `group_concat(distinct c order by c separator ",")` from `test`.`t1` group by `test`.`t1`.`grp`
112
select grp,group_concat(distinct c order by c desc separator ",") from t1 group by grp;
113
grp group_concat(distinct c order by c desc separator ",")
117
select grp,group_concat(c order by grp desc) from t1 group by grp order by grp;
118
grp group_concat(c order by grp desc)
122
select grp, group_concat(a separator "")+0 from t1 group by grp;
123
grp group_concat(a separator "")+0
127
select grp, group_concat(a separator "")+0.0 from t1 group by grp;
128
grp group_concat(a separator "")+0.0
132
select grp, ROUND(group_concat(a separator "")) from t1 group by grp;
133
grp ROUND(group_concat(a separator ""))
138
create table t1 (grp int, c char(10));
139
insert into t1 values (1,NULL),(2,"b"),(2,NULL),(3,"E"),(3,NULL),(3,"D"),(3,NULL),(3,NULL),(3,"D"),(4,""),(5,NULL);
140
select grp,group_concat(c order by c) from t1 group by grp;
141
grp group_concat(c order by c)
147
set group_concat_max_len = 4;
148
select grp,group_concat(c) from t1 group by grp;
156
Warning 1260 1 line(s) were cut by GROUP_CONCAT()
159
Warning 1260 1 line(s) were cut by GROUP_CONCAT()
160
set group_concat_max_len = 1024;
161
select group_concat(sum(c)) from t1 group by grp;
162
ERROR HY000: Invalid use of group function
163
select grp,group_concat(c order by 2) from t1 group by grp;
164
ERROR 42S22: Unknown column '2' in 'order clause'
166
create table t1 ( URL_ID int, URL varchar(80));
167
create table t2 ( REQ_ID int, URL_ID int);
168
insert into t1 values (4,'www.host.com'), (5,'www.google.com'),(5,'www.help.com');
169
insert into t2 values (1,4), (5,4), (5,5);
170
select REQ_ID, Group_Concat(URL) as URL from t1, t2 where
171
t2.URL_ID = t1.URL_ID group by REQ_ID;
175
select REQ_ID, Group_Concat(URL) as URL, Min(t1.URL_ID) urll,
176
Max(t1.URL_ID) urlg from t1, t2 where t2.URL_ID = t1.URL_ID group by REQ_ID;
182
create table t1 (id int, name varchar(16));
183
insert into t1 values (1,'longername'),(1,'evenlongername');
184
select ifnull(group_concat(concat(t1.id, ':', t1.name)), 'shortname') as 'without distinct: how it should be' from t1;
185
without distinct: how it should be
186
1:longername,1:evenlongername
187
select distinct ifnull(group_concat(concat(t1.id, ':', t1.name)), 'shortname') as 'with distinct: cutoff at length of shortname' from t1;
188
with distinct: cutoff at length of shortname
189
1:longername,1:evenlongername
191
create table t1(id int);
192
create table t2(id int);
193
insert into t1 values(0),(1);
194
select group_concat(t1.id) FROM t1,t2;
199
create table t1 (bar varchar(32));
200
insert into t1 values('test1'),('test2');
201
select group_concat(bar order by concat(bar,bar)) from t1;
202
group_concat(bar order by concat(bar,bar))
204
select group_concat(bar order by concat(bar,bar) desc) from t1;
205
group_concat(bar order by concat(bar,bar) desc)
207
select bar from t1 having group_concat(bar)='';
209
select bar from t1 having instr(group_concat(bar), "test") > 0;
212
select bar from t1 having instr(group_concat(bar order by concat(bar,bar) desc), "test2,test1") > 0;
216
create table t1 (a int, a1 varchar(10));
217
create table t2 (a0 int);
218
insert into t1 values (0,"a"),(0,"b"),(1,"c");
219
insert into t2 values (1),(2),(3);
220
select group_concat(a1 order by (t1.a IN (select a0 from t2))) from t1;
221
group_concat(a1 order by (t1.a IN (select a0 from t2)))
223
select group_concat(a1 order by (t1.a)) from t1;
224
group_concat(a1 order by (t1.a))
227
CREATE TABLE t1 (id1 int NOT NULL, id2 int NOT NULL);
228
INSERT INTO t1 VALUES (1, 1),(1, 2),(1, 3),(1, 4),(1, 5),(2, 1),(2, 2),(2, 3);
229
CREATE TABLE t2 (id1 int NOT NULL);
230
INSERT INTO t2 VALUES (1),(2),(3),(4),(5);
231
SELECT t1.id1, GROUP_CONCAT(t1.id2 ORDER BY t1.id2 ASC) AS concat_id FROM t1, t2 WHERE t1.id1 = t2.id1 AND t1.id1=1 GROUP BY t1.id1;
234
SELECT t1.id1, GROUP_CONCAT(t1.id2 ORDER BY t1.id2 ASC) AS concat_id FROM t1, t2 WHERE t1.id1 = t2.id1 GROUP BY t1.id1;
238
SELECT t1.id1, GROUP_CONCAT(t1.id2 ORDER BY t1.id2 DESC) AS concat_id FROM t1, t2 WHERE t1.id1 = t2.id1 GROUP BY t1.id1;
242
SELECT t1.id1, GROUP_CONCAT(t1.id2 ORDER BY 6-t1.id2 ASC) AS concat_id FROM t1, t2 WHERE t1.id1 = t2.id1 GROUP BY t1.id1;
246
SELECT t1.id1, GROUP_CONCAT(t1.id2,6-t1.id2 ORDER BY 6-t1.id2 ASC) AS concat_id FROM t1, t2 WHERE t1.id1 = t2.id1 GROUP BY t1.id1;
250
SELECT t1.id1, GROUP_CONCAT(t1.id2,6-t1.id2 ORDER BY 6-t1.id2 ASC) AS concat_id FROM t1, t2 WHERE t1.id1 = t2.id1 GROUP BY t1.id1;
254
SELECT t1.id1, GROUP_CONCAT(t1.id2,"/",6-t1.id2 ORDER BY 1+0,6-t1.id2,t1.id2 ASC) AS concat_id FROM t1, t2 WHERE t1.id1 = t2.id1 GROUP BY t1.id1;
256
1 5/1,4/2,3/3,2/4,1/5
259
create table t1 (s1 char(10), s2 int not null);
260
insert into t1 values ('a',2),('b',2),('c',1),('a',3),('b',4),('c',4);
261
select distinct s1 from t1 order by s2,s1;
266
select group_concat(distinct s1) from t1;
267
group_concat(distinct s1)
269
select group_concat(distinct s1 order by s2) from t1 where s2 < 4;
270
group_concat(distinct s1 order by s2)
272
select group_concat(distinct s1 order by s2) from t1;
273
group_concat(distinct s1 order by s2)
276
create table t1 (a int, c int);
277
insert into t1 values (1, 2), (2, 3), (2, 4), (3, 5);
278
create table t2 (a int, c int);
279
insert into t2 values (1, 5), (2, 4), (3, 3), (3,3);
280
select group_concat(c) from t1;
283
select group_concat(c order by (select c from t2 where t2.a=t1.a limit 1)) as grp from t1;
286
select group_concat(c order by (select mid(group_concat(c order by a),1,5) from t2 where t2.a=t1.a)) as grp from t1;
289
select group_concat(c order by (select mid(group_concat(c order by a),1,5) from t2 where t2.a=t1.a) desc) as grp from t1;
292
select t1.a, group_concat(c order by (select c from t2 where t2.a=t1.a limit 1)) as grp from t1 group by 1;
297
select t1.a, group_concat(c order by (select mid(group_concat(c order by a),1,5) from t2 where t2.a=t1.a)) as grp from t1 group by 1;
302
select t1.a, group_concat(c order by (select mid(group_concat(c order by a),1,5) from t2 where t2.a=t1.a) desc) as grp from t1 group by 1;
307
select group_concat(c order by (select concat(5-t1.c,group_concat(c order by a)) from t2 where t2.a=t1.a)) as grp from t1;
310
select group_concat(c order by (select concat(t1.c,group_concat(c)) from t2 where a=t1.a)) as grp from t1;
313
select a,c,(select group_concat(c order by a) from t2 where a=t1.a) as grp from t1 order by grp;
320
CREATE TABLE t1 ( a int );
321
CREATE TABLE t2 ( a int );
322
INSERT INTO t1 VALUES (1), (2);
323
INSERT INTO t2 VALUES (1), (2);
324
SELECT GROUP_CONCAT(t1.a*t2.a ORDER BY t2.a) FROM t1, t2 GROUP BY t1.a;
325
GROUP_CONCAT(t1.a*t2.a ORDER BY t2.a)
329
CREATE TABLE t1 (a char(4));
330
INSERT INTO t1 VALUES ('John'), ('Anna'), ('Bill');
331
SELECT GROUP_CONCAT(a SEPARATOR '||') AS names FROM t1
332
HAVING names LIKE '%An%';
335
SELECT GROUP_CONCAT(a SEPARATOR '###') AS names FROM t1
336
HAVING LEFT(names, 1) ='J';
340
CREATE TABLE t1 ( a int, b TEXT );
341
INSERT INTO t1 VALUES (1,'First Row'), (2,'Second Row');
342
SELECT GROUP_CONCAT(b ORDER BY b) FROM t1 GROUP BY a;
343
GROUP_CONCAT(b ORDER BY b)
347
CREATE TABLE t1 (A_ID INT NOT NULL,A_DESC CHAR(3) NOT NULL,PRIMARY KEY (A_ID));
348
INSERT INTO t1 VALUES (1,'ABC'), (2,'EFG'), (3,'HIJ');
349
CREATE TABLE t2 (A_ID INT NOT NULL,B_DESC CHAR(3) NOT NULL,PRIMARY KEY (A_ID,B_DESC));
350
INSERT INTO t2 VALUES (1,'A'),(1,'B'),(3,'F');
351
SELECT t1.A_ID, GROUP_CONCAT(t2.B_DESC) AS B_DESC FROM t1 LEFT JOIN t2 ON t1.A_ID=t2.A_ID GROUP BY t1.A_ID ORDER BY t1.A_DESC;
358
create table t1 (a int, b text);
359
insert into t1 values (1, 'bb'), (1, 'ccc'), (1, 'a'), (1, 'bb'), (1, 'ccc');
360
insert into t1 values (2, 'BB'), (2, 'CCC'), (2, 'A'), (2, 'BB'), (2, 'CCC');
361
select group_concat(b) from t1 group by a;
365
select group_concat(distinct b) from t1 group by a;
366
group_concat(distinct b)
369
select group_concat(b order by b) from t1 group by a;
370
group_concat(b order by b)
373
select group_concat(distinct b order by b) from t1 group by a;
374
group_concat(distinct b order by b)
377
set local group_concat_max_len=4;
378
select group_concat(b) from t1 group by a;
383
Warning 1260 2 line(s) were cut by GROUP_CONCAT()
384
select group_concat(distinct b) from t1 group by a;
385
group_concat(distinct b)
389
Warning 1260 2 line(s) were cut by GROUP_CONCAT()
390
select group_concat(b order by b) from t1 group by a;
391
group_concat(b order by b)
395
Warning 1260 2 line(s) were cut by GROUP_CONCAT()
396
select group_concat(distinct b order by b) from t1 group by a;
397
group_concat(distinct b order by b)
401
Warning 1260 2 line(s) were cut by GROUP_CONCAT()
402
insert into t1 values (1, concat(repeat('1', 300), '2')),
403
(1, concat(repeat('1', 300), '2')), (1, concat(repeat('0', 300), '1')),
404
(2, concat(repeat('1', 300), '2')), (2, concat(repeat('1', 300), '2')),
405
(2, concat(repeat('0', 300), '1'));
406
set local group_concat_max_len=1024;
407
select group_concat(b) from t1 group by a;
409
bb,ccc,a,bb,ccc,1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111112,1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111112,0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
410
BB,CCC,A,BB,CCC,1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111112,1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111112,0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
411
select group_concat(distinct b) from t1 group by a;
412
group_concat(distinct b)
413
bb,ccc,a,1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111112,0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
414
BB,CCC,A,1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111112,0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
415
select group_concat(b order by b) from t1 group by a;
416
group_concat(b order by b)
417
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001,1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111112,1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111112,a,bb,bb,ccc,ccc
418
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001,1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111112,1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111112,A,BB,BB,CCC,CCC
419
select group_concat(distinct b order by b) from t1 group by a;
420
group_concat(distinct b order by b)
421
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001,1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111112,a,bb,ccc
422
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001,1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111112,A,BB,CCC
423
set local group_concat_max_len=400;
424
select group_concat(b) from t1 group by a;
426
bb,ccc,a,bb,ccc,1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111112,1111111111111111111111111111111111111111111111111111111111111111111111111111111111
427
BB,CCC,A,BB,CCC,1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111112,1111111111111111111111111111111111111111111111111111111111111111111111111111111111
429
Warning 1260 2 line(s) were cut by GROUP_CONCAT()
430
select group_concat(distinct b) from t1 group by a;
431
group_concat(distinct b)
432
bb,ccc,a,1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111112,00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
433
BB,CCC,A,1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111112,00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
435
Warning 1260 2 line(s) were cut by GROUP_CONCAT()
436
select group_concat(b order by b) from t1 group by a;
437
group_concat(b order by b)
438
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001,11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
439
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001,11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
441
Warning 1260 2 line(s) were cut by GROUP_CONCAT()
442
select group_concat(distinct b order by b) from t1 group by a;
443
group_concat(distinct b order by b)
444
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001,11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
445
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001,11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
447
Warning 1260 2 line(s) were cut by GROUP_CONCAT()
449
create table t1 (a varchar(255), b varchar(255) );
450
insert into t1 values ('xxx','yyy');
451
select collation(a) from t1;
454
select collation(group_concat(a)) from t1;
455
collation(group_concat(a))
457
create table t2 select group_concat(a) as a from t1;
458
show create table t2;
460
t2 CREATE TABLE `t2` (
463
select collation(group_concat(a,b)) from t1;
464
collation(group_concat(a,b))
468
CREATE TABLE t1 (id int);
469
SELECT GROUP_CONCAT(id) AS gc FROM t1 HAVING gc IS NULL;
473
create table t2 (a int, b int);
474
insert into t2 values (1,1), (2,2);
475
select b x, (select group_concat(x) from t2) from t2;
476
x (select group_concat(x) from t2)
480
create table t1 (d int not null auto_increment,primary key(d), a int, b int, c int);
481
insert into t1(a,b) values (1,3), (1,4), (1,2), (2,7), (1,1), (1,2), (2,3), (2,3);
482
select d,a,b from t1 order by a;
492
explain select a, group_concat(b) from t1 group by a with rollup;
493
id select_type table type possible_keys key key_len ref rows Extra
494
1 SIMPLE t1 ALL NULL NULL NULL NULL 8 Using filesort
495
select a, group_concat(b) from t1 group by a with rollup;
500
select a, group_concat(distinct b) from t1 group by a with rollup;
501
a group_concat(distinct b)
505
select a, group_concat(b order by b) from t1 group by a with rollup;
506
a group_concat(b order by b)
510
select a, group_concat(distinct b order by b) from t1 group by a with rollup;
511
a group_concat(distinct b order by b)
516
create table t1 (a char(3), b char(20), primary key (a, b));
517
insert into t1 values ('ABW', 'Dutch'), ('ABW', 'English');
518
select group_concat(a) from t1 group by b;
524
aID int NOT NULL auto_increment,
525
sometitle varchar(155) NOT NULL default '',
528
UNIQUE KEY sometitle (sometitle)
530
INSERT INTO t1 SET sometitle = 'title1', bID = 1;
531
INSERT INTO t1 SET sometitle = 'title2', bID = 1;
533
bID int NOT NULL auto_increment,
534
somename varchar(155) NOT NULL default '',
536
UNIQUE KEY somename (somename)
538
INSERT INTO t2 SET somename = 'test';
539
SELECT COUNT(*), GROUP_CONCAT(DISTINCT t2.somename SEPARATOR ' |')
540
FROM t1 JOIN t2 ON t1.bID = t2.bID;
541
COUNT(*) GROUP_CONCAT(DISTINCT t2.somename SEPARATOR ' |')
543
INSERT INTO t2 SET somename = 'test2';
544
SELECT COUNT(*), GROUP_CONCAT(DISTINCT t2.somename SEPARATOR ' |')
545
FROM t1 JOIN t2 ON t1.bID = t2.bID;
546
COUNT(*) GROUP_CONCAT(DISTINCT t2.somename SEPARATOR ' |')
548
DELETE FROM t2 WHERE somename = 'test2';
549
SELECT COUNT(*), GROUP_CONCAT(DISTINCT t2.somename SEPARATOR ' |')
550
FROM t1 JOIN t2 ON t1.bID = t2.bID;
551
COUNT(*) GROUP_CONCAT(DISTINCT t2.somename SEPARATOR ' |')
554
create table t1 ( a int not null default 0);
555
select * from (select group_concat(a) from t1) t2;
558
select group_concat('x') UNION ALL select 1;
563
CREATE TABLE t1 (id int, a varchar(9));
564
INSERT INTO t1 VALUES
565
(2, ''), (1, ''), (2, 'x'), (1, 'y'), (3, 'z'), (3, '');
566
SELECT GROUP_CONCAT(a) FROM t1;
569
SELECT GROUP_CONCAT(a ORDER BY a) FROM t1;
570
GROUP_CONCAT(a ORDER BY a)
572
SELECT GROUP_CONCAT(a) FROM t1 GROUP BY id;
577
SELECT GROUP_CONCAT(a ORDER BY a) FROM t1 GROUP BY id;
578
GROUP_CONCAT(a ORDER BY a)
583
create table t1(f1 int);
584
insert into t1 values(1),(2),(3);
585
select f1, group_concat(f1+1) from t1 group by f1 with rollup;
586
f1 group_concat(f1+1)
591
select count(distinct (f1+1)) from t1 group by f1 with rollup;
592
count(distinct (f1+1))
598
create table t1 (f1 int, f2 varchar(255));
599
insert into t1 values (1,repeat('a',255)),(2,repeat('b',255));
600
select f2,group_concat(f1) from t1 group by f2;
601
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
602
def test t1 t1 f2 f2 9 1020 255 Y 0 0 45
603
def group_concat(f1) 9 400 1 Y 128 0 63
605
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 1
606
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb 2
608
create table t1 (a char, b char);
609
insert into t1 values ('a', 'a'), ('a', 'b'), ('b', 'a'), ('b', 'b');
610
create table t2 select group_concat(b) as a from t1 where a = 'a';
611
create table t3 (select group_concat(a) as a from t1 where a = 'a') union
612
(select group_concat(b) as a from t1 where a = 'b');
613
drop table t1, t2, t3;
614
CREATE TABLE t1 (a INT, b LONGTEXT, PRIMARY KEY (a));
615
SET GROUP_CONCAT_MAX_LEN = 20000000;
616
INSERT INTO t1 VALUES (1,REPEAT(CONCAT('A',CAST(CHAR(0) AS BINARY),'B'), 40000));
617
INSERT INTO t1 SELECT a + 1, b FROM t1;
618
SELECT a, CHAR_LENGTH(b) FROM t1;
622
SELECT CHAR_LENGTH( GROUP_CONCAT(b) ) FROM t1;
623
CHAR_LENGTH( GROUP_CONCAT(b) )
625
SET GROUP_CONCAT_MAX_LEN = 1024;
627
CREATE TABLE t1 (a int, b int);
628
INSERT INTO t1 VALUES (2,1), (1,2), (2,2), (1,3);
629
SELECT GROUP_CONCAT(a), x
630
FROM (SELECT a, GROUP_CONCAT(b) x FROM t1 GROUP BY a) AS s
641
insert into t1 values (repeat('a', 1022), 0), (repeat(_utf8 0xc3b7, 4), 0);
642
set group_concat_max_len= 1022 + 10;
643
select @x:=group_concat(x) from t1 group by y;
644
select @@group_concat_max_len, length(@x), char_length(@x), right(@x,12), right(HEX(@x),12);
645
@@group_concat_max_len length(@x) char_length(@x) right(@x,12) right(HEX(@x),12)
646
1032 1031 1027 aaaaaaa,÷÷÷÷ C3B7C3B7C3B7
647
set group_concat_max_len= 1022 + 9;
648
select @x:=group_concat(x) from t1 group by y;
649
select @@group_concat_max_len, length(@x), char_length(@x), right(@x,12), right(HEX(@x),12);
650
@@group_concat_max_len length(@x) char_length(@x) right(@x,12) right(HEX(@x),12)
651
1031 1031 1027 aaaaaaa,÷÷÷÷ C3B7C3B7C3B7
652
set group_concat_max_len= 1022 + 8;
653
select @x:=group_concat(x) from t1 group by y;
654
select @@group_concat_max_len, length(@x), char_length(@x), right(@x,12), right(HEX(@x),12);
655
@@group_concat_max_len length(@x) char_length(@x) right(@x,12) right(HEX(@x),12)
656
1030 1029 1026 aaaaaaaa,÷÷÷ C3B7C3B7C3B7
657
set group_concat_max_len= 1022 + 7;
658
select @x:=group_concat(x) from t1 group by y;
659
select @@group_concat_max_len, length(@x), char_length(@x), right(@x,12), right(HEX(@x),12);
660
@@group_concat_max_len length(@x) char_length(@x) right(@x,12) right(HEX(@x),12)
661
1029 1029 1026 aaaaaaaa,÷÷÷ C3B7C3B7C3B7
662
set group_concat_max_len= 1022 + 6;
663
select @x:=group_concat(x) from t1 group by y;
664
select @@group_concat_max_len, length(@x), char_length(@x), right(@x,12), right(HEX(@x),12);
665
@@group_concat_max_len length(@x) char_length(@x) right(@x,12) right(HEX(@x),12)
666
1028 1027 1025 aaaaaaaaa,÷÷ 612CC3B7C3B7
667
set group_concat_max_len= 1022 + 5;
668
select @x:=group_concat(x) from t1 group by y;
669
select @@group_concat_max_len, length(@x), char_length(@x), right(@x,12), right(HEX(@x),12);
670
@@group_concat_max_len length(@x) char_length(@x) right(@x,12) right(HEX(@x),12)
671
1027 1027 1025 aaaaaaaaa,÷÷ 612CC3B7C3B7
672
set group_concat_max_len= 1022 + 4;
673
select @x:=group_concat(x) from t1 group by y;
674
select @@group_concat_max_len, length(@x), char_length(@x), right(@x,12), right(HEX(@x),12);
675
@@group_concat_max_len length(@x) char_length(@x) right(@x,12) right(HEX(@x),12)
676
1026 1025 1024 aaaaaaaaaa,÷ 6161612CC3B7
677
set group_concat_max_len= 1022 + 3;
678
select @x:=group_concat(x) from t1 group by y;
679
select @@group_concat_max_len, length(@x), char_length(@x), right(@x,12), right(HEX(@x),12);
680
@@group_concat_max_len length(@x) char_length(@x) right(@x,12) right(HEX(@x),12)
681
1025 1025 1024 aaaaaaaaaa,÷ 6161612CC3B7
682
set group_concat_max_len= 1022 + 2;
683
select @x:=group_concat(x) from t1 group by y;
684
select @@group_concat_max_len, length(@x), char_length(@x), right(@x,12), right(HEX(@x),12);
685
@@group_concat_max_len length(@x) char_length(@x) right(@x,12) right(HEX(@x),12)
686
1024 1023 1023 aaaaaaaaaaa, 61616161612C
687
set group_concat_max_len= 1022 + 1;
688
select @x:=group_concat(x) from t1 group by y;
689
select @@group_concat_max_len, length(@x), char_length(@x), right(@x,12), right(HEX(@x),12);
690
@@group_concat_max_len length(@x) char_length(@x) right(@x,12) right(HEX(@x),12)
691
1023 1023 1023 aaaaaaaaaaa, 61616161612C
693
set group_concat_max_len=1024;
694
create table t1 (f1 int, f2 varchar(255));
695
insert into t1 values (1,repeat('a',255)),(2,repeat('b',255));
696
select f2,group_concat(f1) from t1 group by f2;
697
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
698
def test t1 t1 f2 f2 9 1020 255 Y 0 0 45
699
def group_concat(f1) 13 1024 1 Y 128 0 63
701
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 1
702
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb 2
704
CREATE TABLE t1(a TEXT, b CHAR(20));
705
INSERT INTO t1 VALUES ("one.1","one.1"),("two.2","two.2"),("one.3","one.3");
706
SELECT GROUP_CONCAT(DISTINCT UCASE(a)) FROM t1;
707
GROUP_CONCAT(DISTINCT UCASE(a))
709
SELECT GROUP_CONCAT(DISTINCT UCASE(b)) FROM t1;
710
GROUP_CONCAT(DISTINCT UCASE(b))
713
CREATE TABLE t1( a VARCHAR( 10 ), b INT );
714
INSERT INTO t1 VALUES ( repeat( 'a', 10 ), 1),
715
( repeat( 'b', 10 ), 2);
716
SET group_concat_max_len = 20;
717
SELECT GROUP_CONCAT( a ) FROM t1;
721
Warning 1260 1 line(s) were cut by GROUP_CONCAT()
722
SELECT GROUP_CONCAT( DISTINCT a ) FROM t1;
723
GROUP_CONCAT( DISTINCT a )
726
Warning 1260 1 line(s) were cut by GROUP_CONCAT()
727
SELECT GROUP_CONCAT( a ORDER BY b ) FROM t1;
728
GROUP_CONCAT( a ORDER BY b )
731
Warning 1260 1 line(s) were cut by GROUP_CONCAT()
732
SELECT GROUP_CONCAT( DISTINCT a ORDER BY b ) FROM t1;
733
GROUP_CONCAT( DISTINCT a ORDER BY b )
736
Warning 1260 1 line(s) were cut by GROUP_CONCAT()
737
SET group_concat_max_len = DEFAULT;
739
SET group_concat_max_len= 65535;
740
CREATE TABLE t1( a TEXT, b INTEGER );
741
INSERT INTO t1 VALUES ( 'a', 0 ), ( 'b', 1 );
742
SELECT GROUP_CONCAT( a ORDER BY b ) FROM t1;
743
GROUP_CONCAT( a ORDER BY b )
745
SELECT GROUP_CONCAT(DISTINCT a ORDER BY b) FROM t1;
746
GROUP_CONCAT(DISTINCT a ORDER BY b)
748
SELECT GROUP_CONCAT(DISTINCT a) FROM t1;
749
GROUP_CONCAT(DISTINCT a)
751
SET group_concat_max_len= 10;
752
SELECT GROUP_CONCAT(a ORDER BY b) FROM t1;
753
GROUP_CONCAT(a ORDER BY b)
755
SELECT GROUP_CONCAT(DISTINCT a ORDER BY b) FROM t1;
756
GROUP_CONCAT(DISTINCT a ORDER BY b)
758
SELECT GROUP_CONCAT(DISTINCT a) FROM t1;
759
GROUP_CONCAT(DISTINCT a)
761
SET group_concat_max_len= 65535;
762
CREATE TABLE t2( a TEXT );
763
INSERT INTO t2 VALUES( REPEAT( 'a', 5000 ) );
764
INSERT INTO t2 VALUES( REPEAT( 'b', 5000 ) );
765
INSERT INTO t2 VALUES( REPEAT( 'a', 5000 ) );
766
SELECT LENGTH( GROUP_CONCAT( DISTINCT a ) ) FROM t2;
767
LENGTH( GROUP_CONCAT( DISTINCT a ) )
769
CREATE TABLE t3( a TEXT, b INT );
770
INSERT INTO t3 VALUES( REPEAT( 'a', 65534 ), 1 );
771
INSERT INTO t3 VALUES( REPEAT( 'a', 65535 ), 2 );
772
INSERT INTO t3 VALUES( REPEAT( 'a', 65533 ), 3 );
773
SELECT LENGTH( GROUP_CONCAT( a ) ) FROM t3 WHERE b = 1;
774
LENGTH( GROUP_CONCAT( a ) )
776
SELECT LENGTH( GROUP_CONCAT( a ) ) FROM t3 WHERE b = 2;
777
LENGTH( GROUP_CONCAT( a ) )
779
SELECT LENGTH( GROUP_CONCAT( a ) ) FROM t3 WHERE b = 3;
780
LENGTH( GROUP_CONCAT( a ) )
782
SET group_concat_max_len= DEFAULT;
783
DROP TABLE t1, t2, t3;
784
create table t1 (f1 char(20));
785
insert into t1 values (''),('');
786
select group_concat(distinct f1) from t1;
787
group_concat(distinct f1)
789
select group_concat(f1) from t1;
793
CREATE TABLE t1 (a INT, b INT);
794
INSERT INTO t1 VALUES (1, 1), (2, 2), (2, 3);
795
SELECT GROUP_CONCAT(DISTINCT a ORDER BY b) FROM t1;
796
GROUP_CONCAT(DISTINCT a ORDER BY b)
798
SELECT GROUP_CONCAT(DISTINCT a ORDER BY b DESC) FROM t1;
799
GROUP_CONCAT(DISTINCT a ORDER BY b DESC)
801
SELECT GROUP_CONCAT(DISTINCT a) FROM t1;
802
GROUP_CONCAT(DISTINCT a)
804
SELECT GROUP_CONCAT(DISTINCT a + 1 ORDER BY 3 - b) FROM t1;
805
GROUP_CONCAT(DISTINCT a + 1 ORDER BY 3 - b)
807
SELECT GROUP_CONCAT(DISTINCT a + 1 ORDER BY b) FROM t1;
808
GROUP_CONCAT(DISTINCT a + 1 ORDER BY b)
810
SELECT GROUP_CONCAT(a ORDER BY 3 - b) FROM t1;
811
GROUP_CONCAT(a ORDER BY 3 - b)
813
CREATE TABLE t2 (a INT, b INT, c INT, d INT);
814
INSERT INTO t2 VALUES (1,1, 1,1), (1,1, 2,2), (1,2, 2,1), (2,1, 1,2);
815
SELECT GROUP_CONCAT(DISTINCT a, b ORDER BY c, d) FROM t2;
816
GROUP_CONCAT(DISTINCT a, b ORDER BY c, d)
818
SELECT GROUP_CONCAT(DISTINCT a, b ORDER BY d, c) FROM t2;
819
GROUP_CONCAT(DISTINCT a, b ORDER BY d, c)
821
CREATE TABLE t3 (a INT, b INT, c INT);
822
INSERT INTO t3 VALUES (1, 1, 1), (2, 1, 2), (3, 2, 1);
823
SELECT GROUP_CONCAT(DISTINCT a, b ORDER BY b, c) FROM t3;
824
GROUP_CONCAT(DISTINCT a, b ORDER BY b, c)
826
SELECT GROUP_CONCAT(DISTINCT a, b ORDER BY c, b) FROM t3;
827
GROUP_CONCAT(DISTINCT a, b ORDER BY c, b)
829
SELECT GROUP_CONCAT(DISTINCT a, b ORDER BY a, b) FROM t1;
830
GROUP_CONCAT(DISTINCT a, b ORDER BY a, b)
832
SELECT GROUP_CONCAT(DISTINCT b, a ORDER BY a, b) FROM t1;
833
GROUP_CONCAT(DISTINCT b, a ORDER BY a, b)
835
SELECT GROUP_CONCAT(DISTINCT a, b ORDER BY b, a) FROM t1;
836
GROUP_CONCAT(DISTINCT a, b ORDER BY b, a)
838
SELECT GROUP_CONCAT(DISTINCT b, a ORDER BY a, b) FROM t1;
839
GROUP_CONCAT(DISTINCT b, a ORDER BY a, b)
841
SELECT GROUP_CONCAT(DISTINCT a ORDER BY a, b) FROM t1;
842
GROUP_CONCAT(DISTINCT a ORDER BY a, b)
844
SELECT GROUP_CONCAT(DISTINCT b ORDER BY b, a) FROM t1;
845
GROUP_CONCAT(DISTINCT b ORDER BY b, a)
847
SELECT GROUP_CONCAT(DISTINCT a, b ORDER BY a) FROM t1;
848
GROUP_CONCAT(DISTINCT a, b ORDER BY a)
850
SELECT GROUP_CONCAT(DISTINCT b, a ORDER BY b) FROM t1;
851
GROUP_CONCAT(DISTINCT b, a ORDER BY b)
853
DROP TABLE t1, t2, t3;
854
CREATE TABLE t1(a INT);
855
INSERT INTO t1 VALUES (),();
860
GROUP_CONCAT(DISTINCT t1.a) AS d2