042.hive-LEFT SEMI JOIN 、 left anti join、inner join、full join

1. left semi join

类似 in \exists 的功能,但是更高效

a left join  b   若1对多,结果集会出现多条数据,但是left semi join 只会筛选出a表中包含过关联条件的数据不会增加

 

 

2. left anti join

a left anti join b 的功能是在查询过程中,剔除a表中和b表有交集的部分

 

3.

inner join 

返回交集部分

 

4. full join

 

复制代码
CREATE TABLE test001 (
  id                  bigint        ,
  shop_name                  string             COMMENT '门店名称' 
);

CREATE TABLE test002 (
  id                  bigint        ,
  shop_name                  string             COMMENT '门店名称' 
);
 
insert  into  test001( id,shop_name ) values(1,'shop001'),(2,'shop002'),(3,'shop003'),(4,'shop004');
insert  into  test001( id,shop_name ) values (4,'shop00414');
insert  into  test002( id,shop_name ) values(5,'shop001'),(2,'shop002'),(3,'shop003'),(4,'shop004');
insert  into  test002( id,shop_name ) values (4,'shop00424');
复制代码

 

 left semi join

select 
a.* 
from 
    test001  a 
left semi join 
    test002  b 
on a.id =b.id  ;

 

 

 left  join

select 
a.*,b.*
from 
    test001  a 
left  join 
    test002  b 
on a.id =b.id  ;

 

 

 

 

full join

 

select 
a.*,b.*
from 
    test001  a 
full join 
    test002  b 
on a.id =b.id  ;

 

 

inner join

 

select 
a.*,b.*
from 
    test001  a 
inner join 
    test002  b 
on a.id =b.id  ;

 

 

 

 

posted @   star521  阅读(2756)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 一文读懂知识蒸馏
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
历史上的今天:
2021-05-31 006.php-phpstudy启动、php的目录位置查看、浏览器测试
2021-05-31 000.软考-高级-信息项目管理师的总结2021.05.29
点击右上角即可分享
微信分享提示