insert into t1 values (1,1),(2,2),(3,3),(2,2),(4,4),(4,4),(4,4);
insert into t2 values (1,1),(1,1),(1,1),(2,2),(3,3),(3,3),(5,5);
select * from t1 except select * from t2;
a b
4 4
select * from t1 except all select * from t2;
a b
4 4
2 2
4 4
4 4
select * from t1 except all select c+1,d+1 from t2;
a b
1 1
4 4
(select * from t1) except all (select * from t2);
a b
4 4
2 2
4 4
4 4
select * from ((select * from t1) except all (select * from t2)) a;
a b
4 4
2 2
4 4
4 4
select * from ((select a from t1) except all (select c from t2)) a;
a
4
2
4
4
select * from t1 except all select * from t1 union all select * from t1 union all select * from t1 except select * from t2;
a b
4 4
select * from t1 except all select * from t1 union all select * from t1 union all select * from t1 except all select * from t2;
a b
4 4
2 2
4 4
4 4
4 4
4 4
4 4
2 2
2 2
select * from (select * from t1 except all select * from t2) q1 except all select * from (select * from t1 except all select * from t2) q2;
a b
EXPLAIN select * from t1 except all select * from t2;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 7
2 EXCEPT t2 ALL NULL NULL NULL NULL 7
NULL EXCEPT RESULT <except1,2> ALL NULL NULL NULL NULL NULL
EXPLAIN format=json select * from t1 except all select * from t2;
EXPLAIN
{
"query_block": {
"union_result": {
"table_name": "<except1,2>",
"access_type": "ALL",
"query_specifications": [
{
"query_block": {
"select_id": 1,
"table": {
"table_name": "t1",
"access_type": "ALL",
"rows": 7,
"filtered": 100
}
}
},
{
"query_block": {
"select_id": 2,
"operation": "EXCEPT",
"table": {
"table_name": "t2",
"access_type": "ALL",
"rows": 7,
"filtered": 100
}
}
}
]
}
}
}
EXPLAIN extended (select * from t1) except all (select * from t2);
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
2 EXCEPT t2 ALL NULL NULL NULL NULL 7 100.00
NULL EXCEPT RESULT <except1,2> ALL NULL NULL NULL NULL NULL NULL
Warnings:
Note 1003 (/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1`) except all (/* select#2 */ select `test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2`)
EXPLAIN extended select * from ((select * from t1) except all (select * from t2)) a;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 7 100.00
2 DERIVED t1 ALL NULL NULL NULL NULL 7 100.00
3 EXCEPT t2 ALL NULL NULL NULL NULL 7 100.00
NULL EXCEPT RESULT <except2,3> ALL NULL NULL NULL NULL NULL NULL
Note 1003 /* select#1 */ select `a`.`a` AS `a`,`a`.`b` AS `b` from ((/* select#2 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1`) except all (/* select#3 */ select `test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2`)) `a`
Note 1003 /* select#1 */ select `t`.`a` AS `a`,`t`.`b` AS `b`,`t`.`e` AS `e`,`t`.`f` AS `f` from ((/* select#2 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t3`.`e` AS `e`,`test`.`t3`.`f` AS `f` from `test`.`t1` join `test`.`t3`) except all (/* select#3 */ select `test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d`,`test`.`t4`.`g` AS `g`,`test`.`t4`.`h` AS `h` from `test`.`t2` join `test`.`t4`)) `t`
prepare stmt from "(select a,b,e,f from t1,t3) except all (select c,d,g,h from t2,t4)";
execute stmt;
a b e f
1 1 4 4
2 2 4 4
1 1 5 5
2 2 5 5
1 1 4 4
2 2 4 4
2 2 5 5
execute stmt;
a b e f
1 1 4 4
2 2 4 4
1 1 5 5
2 2 5 5
1 1 4 4
2 2 4 4
2 2 5 5
prepare stmt from "select * from ((select a,b,e,f from t1,t3) except all (select c,d,g,h from t2,t4)) a";
execute stmt;
a b e f
1 1 4 4
2 2 4 4
1 1 5 5
2 2 5 5
1 1 4 4
2 2 4 4
2 2 5 5
execute stmt;
a b e f
1 1 4 4
2 2 4 4
1 1 5 5
2 2 5 5
1 1 4 4
2 2 4 4
2 2 5 5
drop tables t1,t2,t3,t4;
select 1 as a from dual except all select 1 from dual;
a
(select 1 from dual) except all (select 1 from dual);
1
(select 1 from dual into @v) except all (select 1 from dual);
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'into @v) except all (select 1 from dual)' at line 1
select 1 from dual ORDER BY 1 except all select 1 from dual;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'except all select 1 from dual' at line 1
select 1 as a from dual union all select 1 from dual;
a
1
1
create table t1 (a int, b blob, a1 int, b1 blob) engine=MyISAM;