1
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);
2
create table t1 (grp int, a bigint unsigned, c char(10) not null, d char(10) not null);
3
3
insert into t1 values (1,1,"a","a");
4
4
insert into t1 values (2,2,"b","a");
5
5
insert into t1 values (2,3,"c","b");
18
18
id select_type table type possible_keys key key_len ref rows filtered Extra
19
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`
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
22
select grp,group_concat(a,c) from t1 group by grp;
23
23
grp group_concat(a,c)
88
88
id select_type table type possible_keys key key_len ref rows filtered Extra
89
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`
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
92
select grp,group_concat(c order by c separator ",") from t1 group by grp;
93
93
grp group_concat(c order by c separator ",")
108
108
id select_type table type possible_keys key key_len ref rows filtered Extra
109
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`
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
112
select grp,group_concat(distinct c order by c desc separator ",") from t1 group by grp;
113
113
grp group_concat(distinct c order by c desc separator ",")
163
163
select grp,group_concat(c order by 2) from t1 group by grp;
164
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);
166
create table t1 ( URL_ID int(11), URL varchar(80));
167
create table t2 ( REQ_ID int(11), URL_ID int(11));
168
168
insert into t1 values (4,'www.host.com'), (5,'www.google.com'),(5,'www.help.com');
169
169
insert into t2 values (1,4), (5,4), (5,5);
170
170
select REQ_ID, Group_Concat(URL) as URL from t1, t2 where
224
224
group_concat(a1 order by (t1.a))
226
226
drop table t1, t2;
227
CREATE TABLE t1 (id1 int NOT NULL, id2 int NOT NULL);
227
CREATE TABLE t1 (id1 tinyint(4) NOT NULL, id2 tinyint(4) NOT NULL);
228
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);
229
CREATE TABLE t2 (id1 tinyint(4) NOT NULL);
230
230
INSERT INTO t2 VALUES (1),(2),(3),(4),(5);
231
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;
447
447
Warning 1260 2 line(s) were cut by GROUP_CONCAT()
449
create table t1 (a varchar(255), b varchar(255) );
449
create table t1 (a varchar(255) character set cp1250 collate cp1250_general_ci,
450
b varchar(255) character set koi8r);
450
451
insert into t1 values ('xxx','yyy');
451
452
select collation(a) from t1;
454
455
select collation(group_concat(a)) from t1;
455
456
collation(group_concat(a))
457
458
create table t2 select group_concat(a) as a from t1;
458
459
show create table t2;
459
460
Table Create Table
460
t2 CREATE TABLE `t2` (
461
t2 CREATE TABLE "t2" (
462
"a" varchar(400) CHARACTER SET cp1250
463
) ENGINE=MyISAM DEFAULT CHARSET=latin1
464
select collation(group_concat(a,_koi8r'test')) from t1;
465
collation(group_concat(a,_koi8r'test'))
467
select collation(group_concat(a,_koi8r 0xC1C2)) from t1;
468
ERROR HY000: Illegal mix of collations (cp1250_general_ci,IMPLICIT) and (koi8r_general_ci,COERCIBLE) for operation 'group_concat'
463
469
select collation(group_concat(a,b)) from t1;
464
collation(group_concat(a,b))
470
ERROR HY000: Illegal mix of collations (cp1250_general_ci,IMPLICIT) and (koi8r_general_ci,IMPLICIT) for operation 'group_concat'
473
CREATE TABLE t1 (a CHAR(10) CHARACTER SET cp850);
474
INSERT INTO t1 VALUES ('�');
478
SELECT GROUP_CONCAT(a) FROM t1;
468
482
CREATE TABLE t1 (id int);
469
483
SELECT GROUP_CONCAT(id) AS gc FROM t1 HAVING gc IS NULL;
523
537
CREATE TABLE t1 (
524
aID int NOT NULL auto_increment,
525
sometitle varchar(155) NOT NULL default '',
538
aID smallint(5) unsigned NOT NULL auto_increment,
539
sometitle varchar(255) NOT NULL default '',
540
bID smallint(5) unsigned NOT NULL,
527
541
PRIMARY KEY (aID),
528
542
UNIQUE KEY sometitle (sometitle)
530
544
INSERT INTO t1 SET sometitle = 'title1', bID = 1;
531
545
INSERT INTO t1 SET sometitle = 'title2', bID = 1;
532
546
CREATE TABLE t2 (
533
bID int NOT NULL auto_increment,
534
somename varchar(155) NOT NULL default '',
547
bID smallint(5) unsigned NOT NULL auto_increment,
548
somename varchar(255) NOT NULL default '',
535
549
PRIMARY KEY (bID),
536
550
UNIQUE KEY somename (somename)
598
create table t1 (f1 int, f2 varchar(255));
612
create table t1 (f1 int unsigned, f2 varchar(255));
599
613
insert into t1 values (1,repeat('a',255)),(2,repeat('b',255));
600
614
select f2,group_concat(f1) from t1 group by f2;
601
615
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
602
def test t1 t1 f2 f2 10 1020 255 Y 0 0 45
603
def group_concat(f1) 10 400 1 Y 128 0 63
616
def test t1 t1 f2 f2 253 255 255 Y 0 0 8
617
def group_concat(f1) 253 400 1 Y 128 0 63
604
618
f2 group_concat(f1)
605
619
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 1
606
620
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb 2
608
623
create table t1 (a char, b char);
609
624
insert into t1 values ('a', 'a'), ('a', 'b'), ('b', 'a'), ('b', 'b');
610
625
create table t2 select group_concat(b) as a from t1 where a = 'a';
611
626
create table t3 (select group_concat(a) as a from t1 where a = 'a') union
612
627
(select group_concat(b) as a from t1 where a = 'b');
628
select charset(a) from t2;
631
select charset(a) from t3;
613
635
drop table t1, t2, t3;
614
CREATE TABLE t1 (a INT, b LONGTEXT, PRIMARY KEY (a));
637
create table t1 (c1 varchar(10), c2 int);
638
select charset(group_concat(c1 order by c2)) from t1;
639
charset(group_concat(c1 order by c2))
642
CREATE TABLE t1 (a INT(10), b LONGTEXT, PRIMARY KEY (a));
615
643
SET GROUP_CONCAT_MAX_LEN = 20000000;
616
644
INSERT INTO t1 VALUES (1,REPEAT(CONCAT('A',CAST(CHAR(0) AS BINARY),'B'), 40000));
617
645
INSERT INTO t1 SELECT a + 1, b FROM t1;
691
720
1023 1023 1023 aaaaaaaaaaa, 61616161612C
693
722
set group_concat_max_len=1024;
694
create table t1 (f1 int, f2 varchar(255));
724
create table t1 (f1 int unsigned, f2 varchar(255));
695
725
insert into t1 values (1,repeat('a',255)),(2,repeat('b',255));
696
726
select f2,group_concat(f1) from t1 group by f2;
697
727
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
698
def test t1 t1 f2 f2 10 1020 255 Y 0 0 45
699
def group_concat(f1) 255 1024 1 Y 128 0 63
728
def test t1 t1 f2 f2 253 255 255 Y 0 0 8
729
def group_concat(f1) 252 1024 1 Y 128 0 63
700
730
f2 group_concat(f1)
701
731
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 1
702
732
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb 2
782
812
SET group_concat_max_len= DEFAULT;
783
813
DROP TABLE t1, t2, t3;
815
create table t1 (id int, name varchar(20)) DEFAULT CHARSET=utf8;
816
insert into t1 (id, name) values (1, "�ra");
817
insert into t1 (id, name) values (2, "�ra");
818
select b.id, group_concat(b.name) from t1 a, t1 b group by b.id;
819
id group_concat(b.name)
823
create table t1(a bit not null default 0);
824
insert into t1 values (), (), ();
825
select group_concat(distinct a) from t1;
826
group_concat(distinct a)
828
select group_concat(distinct a order by a) from t1;
829
group_concat(distinct a order by a)
832
create table t1(a bit(2) not null);
833
insert into t1 values (1), (0), (0), (3), (1);
834
select group_concat(distinct a) from t1;
835
group_concat(distinct a)
837
select group_concat(distinct a order by a) from t1;
838
group_concat(distinct a order by a)
840
select group_concat(distinct a order by a desc) from t1;
841
group_concat(distinct a order by a desc)
844
create table t1(a bit(2), b varchar(10), c bit);
845
insert into t1 values (1, 'a', 0), (0, 'b', 1), (0, 'c', 0), (3, 'd', 1),
846
(1, 'e', 1), (3, 'f', 1), (0, 'g', 1);
847
select group_concat(distinct a, c) from t1;
848
group_concat(distinct a, c)
850
select group_concat(distinct a, c order by a) from t1;
851
group_concat(distinct a, c order by a)
853
select group_concat(distinct a, c) from t1;
854
group_concat(distinct a, c)
856
select group_concat(distinct a, c order by a, c) from t1;
857
group_concat(distinct a, c order by a, c)
859
select group_concat(distinct a, c order by a desc, c desc) from t1;
860
group_concat(distinct a, c order by a desc, c desc)
784
863
create table t1 (f1 char(20));
785
864
insert into t1 values (''),('');
786
865
select group_concat(distinct f1) from t1;