TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

HiveQL - Join

HiveQL - Join with tutorial, introduction, environment setup, first app hello world, state, props, flexbox, height and width, listview, scrollview, images, buttons, router, etc.

<< Back to HIVEQL

HiveQL - JOIN

The HiveQL Join clause is used to combine the data of two or more tables based on a related column between them. The various type of HiveQL joins are: -

  • Inner Join
  • Left Outer Join
  • Right Outer Join
  • Full Outer Join

Here, we are going to execute the join clauses on the records of the following table:

HiveQL - JOIN
HiveQL - JOIN

Inner Join in HiveQL

The HiveQL inner join is used to return the rows of multiple tables where the join condition satisfies. In other words, the join criteria find the match records in every table being joined.

HiveQL - JOIN

Example of Inner Join in Hive

In this example, we take two table employee and employee_department. The primary key (empid) of employee table represents the foreign key (depid) of employee_department table. Let's perform the inner join operation by using the following steps: -

  • Select the database in which we want to create a table.
hive> use hiveql;

HiveQL - JOIN
  • Now, create a table by using the following command:
hive> create table employee(empid int, empname string , state string)
row format delimited
fields terminated by ',' ;

HiveQL - JOIN
  • Load the corresponding data into the table.
hive> load data local inpath '/home/codegyani/hive/employee' into table employee;

HiveQL - JOIN
  • Now, create another table by using the following command:
hive> create table employee_department(depid int, department_name string)
row format delimited
fields terminated by ',' ;

HiveQL - JOIN
  • Load the corresponding data into the table.
hive> load data local inpath '/home/codegyani/hive/employee_department' into table employee_department;

HiveQL - JOIN
  • Now, perform the inner join operation by using the following command: -
hive>select  e1.empname, e2.department_name from employee e1 join employee_department e2 on e1.empid= e2.depid;

HiveQL - JOIN
HiveQL - JOIN
HiveQL - JOIN

Left Outer Join in HiveQL

The HiveQL left outer join returns all the records from the left (first) table and only that records from the right (second) table where join criteria find the match.

HiveQL - JOIN

Example of Left Outer Join in Hive

In this example, we perform the left outer join operation.

  • Let's us execute the left outer join operation by using the following command: -
hive> select  e1.empname, e2.department_name from employee e1 left outer join employee_department e2 on e1.empid= e2.depid;

HiveQL - JOIN
HiveQL - JOIN
HiveQL - JOIN

Right Outer Join in HiveQL

The HiveQL right outer join returns all the records from the right (second) table and only that records from the left (first) table where join criteria find the match.

HiveQL - JOIN

Example of Left Outer Join in Hive

In this example, we perform the left outer join operation.

  • Let's us execute the left outer join operation by using the following command: -
hive> select  e1.empname, e2.department_name from employee e1 right outer join employee_department e2 on e1.empid= e2.depid;

HiveQL - JOIN
HiveQL - JOIN
HiveQL - JOIN

Full Outer Join

The HiveQL full outer join returns all the records from both the tables. It assigns Null for missing records in either table.

HiveQL - JOIN

Example of Full Outer Join in Hive

In this example, we perform the full outer join operation.

  • Let's us execute the full outer join operation by using the following command: -
select  e1.empname, e2.department_name from employee e1 full outer join employee_department e2 on e1.empid= e2.depid;

HiveQL - JOIN
HiveQL - JOIN
HiveQL - JOIN
Next TopicHive




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf