码迷,mamicode.com
首页 > 其他好文 > 详细

hive 常用的 join 操作 实例

时间:2019-06-20 18:48:01      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:str   tab   sql   out   注意   strong   sele   join   val   

test_a 表
id value
1 java
2 python
3 c++
test_b 表
id value
1 java
2 go
3 php
4 c++
1. join

计算的是笛卡尔积,不推荐使用

select * from test_a join test_b on test_a.value = test_b.value;

查询结果: 
java  java 
c++   c++ 
2. left outer join & right outer join

注意:最好将小表放在 左 | 右

select * from test_a left outer join test_b on test_a.value = test_b.value; 

查询结果:
java    java 
python  NULL 
c++     c++ 

select * from test_a right outer join test_b on test_a.value = test_b.value; 

查询结果:
java    java 
NULL    go 
NULL    php 
c++     c++ 
3. full join
select * from test_a full outer join test_b on test_a.value = test_b.value; 

查询结果:
java    java 
python  NULL 
NULL    go 
NULL    php 
c++     c++ 
4. left semi join
select * from test_a left semi join test_b on test_a.value = test_b.value; 
等价于:
select * from test_a left outer join test_b on test_a.value = test_b.value where test_b.value is not null; 

查询结果:
java  java 
c++   c++

hive 常用的 join 操作 实例

标签:str   tab   sql   out   注意   strong   sele   join   val   

原文地址:https://www.cnblogs.com/remainsu/p/hive-chang-yong-de-join-cao-zuo-shi-li.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!