Oracle兼容-语法-MINUS


1. 语法

  1. SELECT ...
  2. MINUS SELECT ...
  3. [MINUS SELECT ...]

2. 定义和用法

MINUS 语法的作用是对两个结果集进行差集计算,不包括重复行。其用法类似 UNIONINTERSECT 语法。

用法同 UNION 操作,不支持右子树嵌套 MINUS,如下例所示:

  1. greatsql> SELECT 1 minus (SELECT 1 MINUS SELECT 1);
  2. ERROR 1235 (42000): This version of MySQL doesn't yet support 'nesting of unions at the right-hand side'

3. 示例

  1. greatsql> SELECT 1,2 MINUS SELECT 'a','b';
  2. +---+---+
  3. | 1 | 2 |
  4. +---+---+
  5. | 1 | 2 |
  6. +---+---+
  7. greatsql> SELECT 1,2 MINUS SELECT 1,2;
  8. Empty set (0.00 sec)
  9. greatsql> CREATE TABLE t1(c1 INT);
  10. greatsql> INSERT INTO t1 VALUES (1),(2),(3),(3);
  11. greatsql> CREATE TABLE t2(c1 INT);
  12. greatsql> INSERT INTO t2 VALUES (1),(2);
  13. greatsql> SELECT * FROM t1 MINUS SELECT * FROM t2;
  14. +------+
  15. | c1 |
  16. +------+
  17. | 3 |
  18. +------+

问题反馈

联系我们

扫码关注微信公众号

greatsql-wx