23
23
(select a,b from t1 limit 2) union all (select a,b from t2 order by a) limit 4;
24
24
(select a,b from t1 limit 2) union all (select a,b from t2 order by a limit 1);
25
25
(select a,b from t1 limit 2) union all (select a,b from t2 order by a limit 1) order by b desc;
26
--error ER_TABLENAME_NOT_ALLOWED_HERE
27
27
(select a,b from t1 limit 2) union all (select a,b from t2 order by a limit 1) order by t1.b;
28
28
--replace_column 9 #
29
29
explain extended (select a,b from t1 limit 2) union all (select a,b from t2 order by a limit 1) order by b desc;
39
39
--replace_column 9 #
40
40
explain select a,b from t1 union all select a,b from t2;
42
--error ER_BAD_FIELD_ERROR
43
43
explain select xx from t1 union select 1;
44
--error ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT
45
45
explain select a,b from t1 union select 1;
46
--error ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT
47
47
explain select 1 union select a,b from t1 union select 1;
48
--error ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT
49
49
explain select a,b from t1 union select 1 limit 0;
51
--error ER_WRONG_USAGE
52
52
select a,b from t1 into outfile 'skr' union select a,b from t2;
54
--error ER_WRONG_USAGE
55
55
select a,b from t1 order by a union select a,b from t2;
57
--error ER_WRONG_USAGE
58
58
insert into t3 select a from t1 order by a union select a from t2;
60
--error ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT
61
61
create table t3 select a,b from t1 union select a from t2;
63
--error ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT
64
64
select a,b from t1 union select a from t2;
66
--error ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT
67
67
select * from t1 union select a from t2;
69
--error ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT
70
70
select a from t1 union select * from t2;
72
--error ER_CANT_USE_OPTION_HERE
73
73
select * from t1 union select SQL_BUFFER_RESULT * from t2;
75
75
# Test CREATE, INSERT and REPLACE
84
84
# Test some unions without tables
86
--error ER_NO_TABLES_USED
87
87
select * union select 1;
88
88
select 1 as a,(select a union select a);
89
--error ER_BAD_FIELD_ERROR
90
90
(select 1) union (select 2) order by 0;
91
91
SELECT @a:=1 UNION SELECT @a:=@a+1;
92
--error ER_BAD_FIELD_ERROR
93
93
(SELECT 1) UNION (SELECT 2) ORDER BY (SELECT a);
94
94
(SELECT 1,3) UNION (SELECT 2,1) ORDER BY (SELECT 2);
250
250
(SELECT * FROM t1 ORDER by a) UNION ALL (SELECT * FROM t2 ORDER BY a) ORDER BY A desc LIMIT 4;
253
--error ER_CANT_USE_OPTION_HERE
254
254
(SELECT * FROM t1) UNION all (SELECT SQL_CALC_FOUND_ROWS * FROM t2) LIMIT 1;
256
256
create temporary table t1 select a from t1 union select a from t2;
257
257
drop temporary table t1;
258
--error ER_UPDATE_TABLE_USED
259
259
create table t1 select a from t1 union select a from t2;
260
--error ER_BAD_FIELD_ERROR
261
261
select a from t1 union select a from t2 order by t2.a;
262
262
drop table t1,t2;
316
316
insert into t2 (group_name) values ('Group A');
317
317
insert into t2 (group_name) values ('Group B');
318
318
insert into t3 (user_id, group_id) values (1,1);
319
select 1 'is_in_group', a.user_name, c.group_name, b.id from t1 a, t3 b, t2 c where a.id = b.user_id and b.group_id = c.id UNION select 0 'is_in_group', a.user_name, c.group_name, null from t1 a, t2 c;
319
select 1 'is_in_group', a.user_name, c.group_name, b.id from t1 a, t3 b, t2 c where a.id = b.user_id and b.group_id = c.id UNION select 0 'is_in_group', a.user_name, c.group_name, null from t1 a CROSS JOIN t2 c;
320
320
drop table t3, t1, t2;
436
436
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
437
437
show create table t1;
439
--error ER_BAD_FIELD_ERROR
439
440
create table t1 select _latin1"test" union select _latin1"testt" ;
441
--error ER_BAD_FIELD_ERROR
440
442
create table t1 select _utf8"test" union select _utf8"testt" ;
441
443
create table t1 select "test" union select "testt" ;
442
444
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
457
457
insert into t1 select * from t2;
458
458
insert into t2 select * from t1;
459
459
set local tmp_table_size=1024;
460
select count(*) from (select * from t1 union all select * from t2 order by 1) b;
460
select SQL_BIG_RESULT count(*) from (select SQL_BIG_RESULT * from t1 union all select * from t2 order by 1) b;
461
461
select count(*) from t1;
462
462
select count(*) from t2;
463
463
drop table t1,t2;
549
549
CREATE TABLE t1 (i int default NULL,c char(1) default NULL,KEY i (i));
550
550
CREATE TABLE t2 (i int default NULL,c char(1) default NULL,KEY i (i));
551
--error ER_BAD_FIELD_ERROR
552
552
explain (select * from t1) union (select * from t2) order by not_existing_column;
553
553
drop table t1, t2;
602
602
create table t3 (a ENUM('Yes', 'No') NOT NULL);
603
603
create table t4 (a ENUM('aaa', 'bbb') NOT NULL);
604
604
insert into t3 values (1);
605
--error 1691 # Bad enum
605
--error ER_INVALID_ENUM_VALUE # Bad enum
606
606
insert into t4 values (3);
607
607
select "1" as a union select a from t1;
608
608
select a as a from t1 union select "1";
661
661
create table t2 (
662
662
a char collate utf8_swedish_ci,
663
663
b char collate utf8_spanish_ci);
664
--error ER_CANT_AGGREGATE_NCOLLATIONS
665
665
create table t1 as
666
666
(select a from t2) union
667
667
(select b from t2);
669
--error ER_WRONG_COLUMN_NAME
670
670
create table t1 as
671
671
(select a collate utf8_swedish_ci from t2) union
672
672
(select b from t2);
746
746
# Bug#15949 union + illegal mix of collations (IMPLICIT + COERCIBLE)
748
748
select concat('a', 'b' collate utf8_bin);
749
create table t1 (foo varchar(100)) collate utf8_bin;
749
create table t1 (foo varchar(100)) collate=utf8_bin;
750
750
insert into t1 (foo) values ("foo");
751
--error ER_TABLE_UNKNOWN
752
752
select foo from t1 union select 'bar' as foo from dual;
753
753
select foo from t1 union select 'bar' as foo;
956
956
INSERT INTO t1 VALUES (3),(1),(2),(4),(1);
958
958
SELECT a FROM (SELECT a FROM t1 UNION SELECT a FROM t1 ORDER BY a) AS test;
959
--error ER_BAD_FIELD_ERROR
960
960
SELECT a FROM (SELECT a FROM t1 UNION SELECT a FROM t1 ORDER BY c) AS test;