oracle basic accumulation -union and union all the difference

Scene:
    Fundamentals query
environment:
    . The Oracle Database 11g; PL / the SQL Developer
1. Data
1.1 Table SENSOR_COLLECT_DATA_A
     
1.2 Table II SENSOR_COLLECT_DATA_B
     
2. Union
    Union two result sets and set operations, not including the duplicate records, according to the default rules It sorts.

 select *
  from sensor_collect_data_a  
union
select *
  from sensor_collect_data_b  

      
All Union 3.
   Union All the results of the two sets and set operations, including duplicate records are not sorted.

 select *
  from sensor_collect_data_a
union all
select *
  from sensor_collect_data_b

     
4 Statement of Attached Table
4.1 to build a table statement

create table SENSOR_COLLECT_DATA_A
(
  sensor_id NUMBER(16) not null,
  region    VARCHAR2(16) not null,
  s1        NUMBER(6,3),
  s2        NUMBER(6,3),
  s3        NUMBER(6,3)
);
comment on table SENSOR_COLLECT_DATA_A
  is '传感器采集数据';
comment on column SENSOR_COLLECT_DATA_A.sensor_id
  is '数据id实体唯一标识';
comment on column SENSOR_COLLECT_DATA_A.region
  is '传感器安装区域';
comment on column SENSOR_COLLECT_DATA_A.s1
  is '传感器采集的值1';
comment on column SENSOR_COLLECT_DATA_A.s2
  is '传感器采集的值2';
comment on column SENSOR_COLLECT_DATA_A.s3
  is '传感器采集的值3';
insert into SENSOR_COLLECT_DATA_A (sensor_id, region, s1, s2, s3)
values (20191618, '2019', 2.22, 3.22, 3.33);
insert into SENSOR_COLLECT_DATA_A (sensor_id, region, s1, s2, s3)
values (20191619, '2019', 3.22, 3.33, 3.55);
insert into SENSOR_COLLECT_DATA_A (sensor_id, region, s1, s2, s3)
values (20191620, '2019', 1.22, 2.22, 3.22);
commit;

Table 4.2 build two statements

create table SENSOR_COLLECT_DATA_B
(
  sensor_id NUMBER(16) not null,
  region    VARCHAR2(16) not null,
  s1        NUMBER(6,3),
  s2        NUMBER(6,3),
  s3        NUMBER(6,3)
);
comment on table SENSOR_COLLECT_DATA_B
  is '传感器采集数据';
comment on column SENSOR_COLLECT_DATA_B.sensor_id
  is '数据id实体唯一标识';
comment on column SENSOR_COLLECT_DATA_B.region
  is '传感器安装区域';
comment on column SENSOR_COLLECT_DATA_B.s1
  is '传感器采集的值1';
comment on column SENSOR_COLLECT_DATA_B.s2
  is '传感器采集的值2';
comment on column SENSOR_COLLECT_DATA_B.s3
  is '传感器采集的值3';
insert into SENSOR_COLLECT_DATA_B (sensor_id, region, s1, s2, s3)
values (20191617, '2019', 1.22, 2.22, 3.22);
insert into SENSOR_COLLECT_DATA_B (sensor_id, region, s1, s2, s3)
values (20191616, '2019', 1.33, 2.33, 3.33);
insert into SENSOR_COLLECT_DATA_B (sensor_id, region, s1, s2, s3)
values (20191618, '2019', 2.22, 3.22, 3.33);
commit;

Above, thanks.

He published 183 original articles · won praise 40 · Views 150,000 +

Guess you like

Origin blog.csdn.net/zhangbeizhen18/article/details/101002496