Hive join tables and keep only 1 column

93 Views Asked by At

I have below table join and noticed that Hive keeps two copies of the pk column - one from table b and one from table c. Is there a way to keep only 1 of those columns?

I can always replace select * with exact select column1, column2 etc but that wont be too efficient

with a as (
select 
*
from table1 b left join table2 c 
on b.pk = c.pk

)
select 
*
from a;

;

#update 1

is it possible to alias many columns? for example the below line works

select b.pk as duplicate_pk

but is there a way to do something like select b.* as table2 to add text table2 before all the columns of the table b?

1

There are 1 best solutions below

1
Raid On

Not sure if you already tried this but you can choose what to select using either

b.* to select cols of only table1

c.* to select cols of only table2

Example:

with a as (
select 
b.*
from table1 b left join table2 c 
on b.pk = c.pk
)
select 
*
from a;