hive 常用的 join 操作 实例

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++
posted @ 2019-06-20 18:36  remainsu  阅读(651)  评论(0编辑  收藏  举报