0% found this document useful (0 votes)
55 views3 pages

Arun P Rangrej 4 Sem, Mca RIT Hive-Handout: Create The Following Tables and Answer The Queries

The document describes how to create tables in Hive and perform different types of joins between the tables. It includes: - Creating two tables, one called "animal" with columns id_a and a_name, and one called "eat" with columns id_e and eats. - Inserting sample data into the tables. - Examples of inner, left outer, right outer, and full outer joins between the tables to retrieve different combinations of column values. - Queries returning joined data from the tables based on the primary key columns id_a and id_e.

Uploaded by

Arun Rangrej
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views3 pages

Arun P Rangrej 4 Sem, Mca RIT Hive-Handout: Create The Following Tables and Answer The Queries

The document describes how to create tables in Hive and perform different types of joins between the tables. It includes: - Creating two tables, one called "animal" with columns id_a and a_name, and one called "eat" with columns id_e and eats. - Inserting sample data into the tables. - Examples of inner, left outer, right outer, and full outer joins between the tables to retrieve different combinations of column values. - Queries returning joined data from the tables based on the primary key columns id_a and id_e.

Uploaded by

Arun Rangrej
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Arun P Rangrej

4th SEM, MCA


RIT

HIVE-HANDOUT
Create the following tables and answer the queries.

ID_A A_Name ID_E Eats


1 Elephant 1 Grass
2 Monkey 3 Fish
3 Cat 4 Meat
4 Dog 6 Goldfish Food
8 Goat 7 Lettuce
10 Pig 8 Flowers
11 Mouse 10 Anything

ANS:
create database arun;

Create table animal:


create table if not exists arun.animal(id_aint,a_name string)
row format delimited
fields terminated by ',';
Insert values:
insert into arun.animal(id_a,a_name) values (1,"elephant")
insert into arun.animal(id_a,a_name) values (2,"monkey")
insert into arun.animal(id_a,a_name) values (3,"cat")
insert into arun.animal(id_a,a_name) values (4,"dog")
insert into arun.animal(id_a,a_name) values (8,"goat")
insert into arun.animal(id_a,a_name) values (10,"pig")
insert into arun.animal(id_a,a_name) values (11,"mouse")

Create table eat:


create table if not exists arun.eat(id_eint,eats string)
row format delimited
fields terminated by ',' ;

Insert values:
insert into arun.eat(id_e,eats) values (1,"grass")
insert into arun.eat(id_e,eats) values (3,"fish")
insert into arun.eat(id_e,eats) values (4,"meat")
insert into arun.eat(id_e,eats) values (6,"goldfish food")
insert into arun.eat(id_e,eats) values (7,"lettuce")
insert into arun.eat(id_e,eats) values (8,"flowers")
insert into arun.eat(id_e,eats) values (10,"anything")

Q1. Obtain the results using an Inner Join as follows


ID_A A_Name ID_E Eats
1 Elephant 1 Grass
3 Cat 3 Fish
4 Dog 4 Meat
8 Goat 8 Flowers
10 Pig 10 Anything

ANS:
SELECT a.id_a, a.a_name, f.id_e, f.eats
FROM arun.animal a JOIN arun.eat f
ON (a.id_a = f.id_e);

Q2. Obtain the results using a Left Outer Join as follows

ID_A A_Name ID_E Eats


1 Elephant 1 Grass
2 Monkey NULL NULL
3 Cat 3 Fish
4 Dog 4 Meat
8 Goat 8 Flowers
10 Pig 10 Anything
11 Mouse NULL NULL

ANS:

SELECT a.id_a, a.a_name, f.id_e, f.eats


FROM arun.animal a
LEFT OUTER JOIN arun.eat f
ON (a.id_a = f.id_e);

Q3. Obtain the results using a Right Outer Join as follows

ID_A A_Name ID_E Eats


1 Elephant 1 Grass
3 Cat 3 Fish
4 Dog 4 Meat
NULL NULL 6 Goldfish Food
NULL NULL 7 Lettuce
8 Goat 8 Flowers
10 Pig 10 Anything
ANS:
SELECT a.id_a, a.a_name, f.id_e, f.eats
FROM arun.animal a
RIGHT OUTER JOIN arun.eat f
ON (a.id_a = f.id_e);

Q4. Obtain the results using a Full Outer Join as follows

ID_A A_Name ID_E Eats


1 Elephant 1 Grass
2 Monkey NULL NULL
3 Cat 3 Fish
4 Dog 4 Meat
NULL NULL 6 Goldfish Food
NULL NULL 7 Lettuce
8 Goat 8 Flowers
10 Pig 10 Anything
11 Mouse NULL NULL
ANS:

SELECT a.id_a, a.a_name, f.id_e, f.eats


FROM arun.animal a

You might also like