Hive join query for performance

2019-09-17 11:10发布

问题:

I want to left join Table A with B on A.id=B.id like below:

select A.id,B.name from (select * from TABLEa)A 
LEFT JOIN (select * from TABLEb where partition IN ('GOP','LOP')B on A.id=B.id

here my TABLEb is partitioned by two values GOP and LOP.

I also tried to do same query on following approach:

insert overwrite table final 
select A.id,B.name from (select * from TABLEa)A 
LEFT JOIN (select * from TABLEb where partition IN ('GOP')B on A.id=B.id;
insert INTOtable final 
select A.id,B.name from (select * from TABLEa)A 
LEFT JOIN (select * from TABLEb where partition IN ('LOP')B on A.id=B.id;

Can any body tell which approach should be better? and reason or what makes second different than first one.

please help

回答1:

select
    A.id,
    B.name
from
    TABLEa as A 
    LEFT JOIN TABLEb as B on partition IN ('GOP','LOP') and A.id=B.id


标签: sql hadoop hive