HiveSQL DQL join与union

3.3join 查询

将多个表通过字段关联在一起,形成查询结果
创建 student_location 表,存储学生的地理位置信息

CREATE TABLE student_location( id string comment 'stdno',
province string comment 'province name', city string comment 'city name',
region string comment 'region name'
)
comment 'student location info' ROW FORMAT DELIMITED
FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n'

构造 student_location 表数据

001	河北省	石家庄市	高新区

将数据加载进 student_location 表中

LOAD DATA LOCAL INPATH './student_location.txt' OVERWRITE INTO TABLE student_location;

join 查询示例
inner join
将左表和右表满足联接条件的数据,全部查询出来

select * from  student 
inner join student_location
on student.id=student_location.id;

left outer join
以左表为主,将左表数据全部保留,没有关联上数据字段置成 NULL

select * from student 
left outer join student_location
on student.id=student_location.id;

right outer join
以右表为主,将右表数据全部保留,没有关联上数据字段置成 NULL

select * from student
right outer join student_location 
on student.id=student_location.id;

full outer join
没有关联上数据字段全部置成 NULL

select * from student
full outer join student_location 
on student.id=student_location.id;

3.4union

union all
将所有表数据,完全叠加在一起,不去重。要求:所有表的字段和类型完全一致。
以 student 和 student_outer 表为例

select * from student 
union all
select * from student_outer;

union
将所有表数据,完全叠加在一起,总体去重。要求:所有表的字段和类型完全一致。
以 student 和 student_outer 表为例

select * from student 
union
select * from student_outer;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值