HiveQL Join Types - ignacio-alorre/Hive GitHub Wiki

Different types of Joins in HiveQL

Source Code

We start with the following two tables:

Customers
Note: There is a duplicated record in this table
cust

Segments
Note: There is one record with null value for the join key (segment) and two records with same join key seg

1- Join

Returns only elements which join key (segment) is present in both tables

j1
select c.*, o.discount from
D_customer c join D_offers o
on c.segment = o.segment
join1

2- Full Join

Returns all the records from both tables. Those rows without a join key (segment) in both tables will fill missing fields with null.

j2
select c.*, o.discount from
D_customer c full join D_offers o
on c.segment = o.segment
join2

3- Left Outer Join

Returns all elements from the left table. Where there is a match in the join key (segment) between both table, the record is enriched with attributes from the right table. Where there is no match, missing values are filled with null

j3
select c.*, o.discount from
D_customer c left outer join D_offers o
on c.segment = o.segment
join3

4- Left Outer Join with Exclusion

Returns those rows from the left table which join key (segment) is not present in the right table

j4
select c.*, o.discount from
D_customer c join D_offers o
on c.segment = o.segment
where o.segment is null
join4

5- Right Outer Join

Returns all elements from the right table. Where there is a match in the join key (segment) between both table, the record is enriched with attributes from the left table. Where there is no match, missing values are filled with null

j5
select c.*, o.discount from
D_customer c right outer join D_offers o
on c.segment = o.segment
join5

6- Right Outer Join with Exclusion

Returns those rows from the right table which join key (segment) is not present in the left table

j6
select c.*, o.* from
D_customer c right outer join D_offers o
on c.segment = o.segment
where c.segment is null
join6

7- Full Outer Join with Exclusion

Only elements which join key (segment) is present in just one of the tables

j7
select c.*, o.discount from
D_customer c full outer join D_offers o
on c.segment = o.segment
where o.segment is null
or c.segment is null
join7
⚠️ **GitHub.com Fallback** ⚠️