zoukankan      html  css  js  c++  java
  • union 和 union all的区别

    union 和 union all的区别

    相同点和不同点

    相同点:
    union和union all 都是对于多个查询结果的并集进行操作
    不同点:
    1.union 不会输出两个结果并集的重复行
    2.union all 会输出两个结果并集的重复行

    实验表

    字段解释:
    xh:学号
    xh:姓名
    nl:年龄

    create table student(xh number,xm varchar2(4),nl int);
    insert into student values(1,'A',21);
    insert into student values(2,'B',21);
    insert into student values(3,'A',21);
    insert into student values(4,'A',21);
    insert into student values(5,'A',21);
    insert into student values(6,'C',21);
    insert into student values(7,'B',21);
    

    查看表

    SQL> select * from student;
    
        XH XM           NL
    ---------- ------------ ----------
         1 A            21
         2 B            21
         3 A            21
         4 A            21
         5 A            21
         6 C            21
         7 B            21
    
    7 rows selected.
    
    SQL> 
    

    例子

    union

    SQL> select * from student
      2  union
      3  select * from student where xm='A';
    
        XH XM           NL
    ---------- ------------ ----------
         1 A            21
         2 B            21
         3 A            21
         4 A            21
         5 A            21
         6 C            21
         7 B            21
    
    7 rows selected.
    

    union all

    SQL> select * from student
      2  union all
      3  select * from student where xm='A';
    
        XH XM           NL
    ---------- ------------ ----------
         1 A            21
         2 B            21
         3 A            21
         4 A            21
         5 A            21
         6 C            21
         7 B            21
         1 A            21
         3 A            21
         4 A            21
         5 A            21
    
    11 rows selected.
    
    SQL> 
    

      

  • 相关阅读:
    降维
    latex 中文
    Java基础——通信
    Java基础——文件读取
    Java基础——哈弗曼树的Java实现(构建、遍历输出、哈弗曼编码)
    Java基础——表达式二叉树的Java实现构建(构建+前序、中序、后序遍历)
    MYSQL和ORACLE的一些区别
    快速排序
    冒泡排序
    希尔排序
  • 原文地址:https://www.cnblogs.com/Jansens520/p/11466509.html
Copyright © 2011-2022 走看看