insert into t2 values (4), (5), (9), (1), (8), (9);
create table t3 (a int);
insert into t3 values (8), (1), (8), (2), (3), (7), (2);
select * from t1 where a > 4
union all
select * from t2 where a < 5
intersect
select * from t3 where a < 5;
a
7
7
1
explain extended
select * from t1 where a > 4
union all
select * from t2 where a < 5
intersect
select * from t3 where a < 5;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 7 100.00 Using where
4 UNION <derived2> ALL NULL NULL NULL NULL 6 100.00
2 DERIVED t2 ALL NULL NULL NULL NULL 6 100.00 Using where
3 INTERSECT t3 ALL NULL NULL NULL NULL 7 100.00 Using where
NULL INTERSECT RESULT <intersect2,3> ALL NULL NULL NULL NULL NULL NULL
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` > 4 union all /* select#4 */ select `__4`.`a` AS `a` from (/* select#2 */ select `test`.`t2`.`a` AS `a` from `test`.`t2` where `test`.`t2`.`a` < 5 intersect /* select#3 */ select `test`.`t3`.`a` AS `a` from `test`.`t3` where `test`.`t3`.`a` < 5) `__4`