当前位置: 代码迷 >> 综合 >> union 和 union all
  详细解决方案

union 和 union all

热度:93   发布时间:2024-01-28 03:46:09.0

1. 上结论

union : 不仅会表间去重,还会表内去重

union all :不去重

2. 实验

2.1 建表

Create table adst.hyy_test1
(name string 
); Create table adst.hyy_test2 
(name string
) ;

2.2 插入数据

insert into adst.hyy_test1 values('hyy');
insert into adst.hyy_test1 values('hyy');
insert into adst.hyy_test2 values('hyy');
insert into adst.hyy_test2 values('hyy');
select * from adst.hyy_test1; -- hyy hyyselect * from adst.hyy_test2; -- hyy hyy

2.3 union  和 union all  操作

select * from adst.hyy_test1
union
select * from adst.hyy_test2;
-- hyyselect * from adst.hyy_test1
union all
select * from adst.hyy_test2;
-- hyy
-- hyy
-- hyy
-- hyy