当前位置: 代码迷 >> 综合 >> MariaDB 10.3支持EXCEPT、INTERSECT语法
  详细解决方案

MariaDB 10.3支持EXCEPT、INTERSECT语法

热度:25   发布时间:2023-12-20 23:47:48.0

EXCEPT 返回两个结果集的差

 

INTERSECT 返回两个结果集的交集

 

举例说明:

mysql> CREATE TABLE t1 (id INT);
Query OK, 0 rows affected (0.00 sec)mysql> CREATE TABLE t2 (id INT);
Query OK, 0 rows affected (0.01 sec)mysql> INSERT INTO t1 VALUES (1),(2),(3),(4),(5),(6);
Query OK, 6 rows affected (0.00 sec)
Records: 6  Duplicates: 0  Warnings: 0mysql> INSERT INTO t2 VALUES (1),(2),(3);
Query OK, 3 rows affected (0.00 sec)
Records: 3  Duplicates: 0  Warnings: 0mysql> select * from t1 EXCEPT select * from t2;
+------+
| i    |
+------+
|    4 |
|    5 |
|    6 |
+------+
3 rows in set (0.00 sec)mysql> select * from t1  INTERSECT select * from t2 ;
+------+
| i    |
+------+
|    1 |
|    2 |
|    3 |
+------+
3 rows in set (0.00 sec)

 

注:MySQL 8.0不支持该语法。

  相关解决方案