C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
HiveQL - JOINThe 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: -
Here, we are going to execute the join clauses on the records of the following table: Inner Join in HiveQLThe 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. Example of Inner Join in HiveIn 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: -
hive> use hiveql;
hive> create table employee(empid int, empname string , state string) row format delimited fields terminated by ',' ;
hive> load data local inpath '/home/codegyani/hive/employee' into table employee;
hive> create table employee_department(depid int, department_name string) row format delimited fields terminated by ',' ;
hive> load data local inpath '/home/codegyani/hive/employee_department' into table employee_department;
hive>select e1.empname, e2.department_name from employee e1 join employee_department e2 on e1.empid= e2.depid; Left Outer Join in HiveQLThe 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. Example of Left Outer Join in HiveIn this example, we perform the left outer join operation.
hive> select e1.empname, e2.department_name from employee e1 left outer join employee_department e2 on e1.empid= e2.depid; Right Outer Join in HiveQLThe 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. Example of Left Outer Join in HiveIn this example, we perform the left outer join operation.
hive> select e1.empname, e2.department_name from employee e1 right outer join employee_department e2 on e1.empid= e2.depid; Full Outer JoinThe HiveQL full outer join returns all the records from both the tables. It assigns Null for missing records in either table. Example of Full Outer Join in HiveIn this example, we perform the full outer join operation.
select e1.empname, e2.department_name from employee e1 full outer join employee_department e2 on e1.empid= e2.depid;
Next TopicHive
|