Hive query Join tables based on ID

0 votes

Hello,
I have 2 tables as below with the data loaded as below, I need a query to join 2 tables on id whenever the charge is -ve values, there should not be any duplicate values 
ex:id 20 has 2 transactions each with charge -1:00 since the charge is -ve we should not see duplicate values in the joined query for id 20.
Please help me with the query

create table a1
(
id int,
name string
)
row format delimited fields terminated by ","
stored as textfile

create table b1
(
id int,
charge float
)
row format delimited fields terminated by ","
stored as textfile


INSERT INTO a1 values 
(10, "sant"),
(20, "suvi"),
(25, "kal"),
(26, "deep"),
(27, "satya"),
(30, "manju")

INSERT INTO b1 values 
(10, 1.00),
(20, -1.00),
(25, 1.00),
(26, -1.00),
(27, 1.00),
(28, -1.00),
(20, -1.00),
(26, -1.00),
(28, -1.00),
(10, 2.00)
Jul 25, 2019 in Big Data Hadoop by Ramya
905 views

1 answer to this question.

0 votes

After creating the tables a1 and b1 and loading data in it, follow the below steps,

1) We will create a new table as below,

create table b2
(
id int,
charge float
)
stored as textfile;

2) Load data in this table,

insert into table b2 select id, charge from b1 group by id, charge having charge > 0;

3) Display the desired result,

select a.name, b.id, b.charge from a1 a join b2 b on (a.id = b.id);
answered Jul 25, 2019 by Tarun

Related Questions In Big Data Hadoop

0 votes
1 answer

Query regarding Temporary table's metadata in HIVE

Registered tables are not cached in memory. ...READ MORE

answered May 22, 2019 in Big Data Hadoop by Tina
1,441 views
0 votes
1 answer

How to get resource utilized(memory and CPU) by each hive query which is running under single application Id?

Hi@sivachandran, You can monitor the metrics of your ...READ MORE

answered Sep 18, 2020 in Big Data Hadoop by MD
• 95,460 points
2,667 views
0 votes
1 answer

How Impala is fast compared to Hive in terms of query response?

Impala provides faster response as it uses MPP(massively ...READ MORE

answered Mar 21, 2018 in Big Data Hadoop by nitinrawat895
• 11,380 points
2,216 views
0 votes
1 answer

Setting Hive/Hadoop property using Hive Query

You can set Hadoop & Hive conf ...READ MORE

answered Apr 18, 2018 in Big Data Hadoop by Shubham
• 13,490 points
1,975 views
+1 vote
1 answer

Hadoop Mapreduce word count Program

Firstly you need to understand the concept ...READ MORE

answered Mar 16, 2018 in Data Analytics by nitinrawat895
• 11,380 points
11,028 views
0 votes
1 answer

hadoop.mapred vs hadoop.mapreduce?

org.apache.hadoop.mapred is the Old API  org.apache.hadoop.mapreduce is the ...READ MORE

answered Mar 16, 2018 in Data Analytics by nitinrawat895
• 11,380 points
2,536 views
+2 votes
11 answers

hadoop fs -put command?

Hi, You can create one directory in HDFS ...READ MORE

answered Mar 16, 2018 in Big Data Hadoop by nitinrawat895
• 11,380 points
108,832 views
–1 vote
1 answer

Hadoop dfs -ls command?

In your case there is no difference ...READ MORE

answered Mar 16, 2018 in Big Data Hadoop by kurt_cobain
• 9,350 points
4,612 views
+1 vote
1 answer

Hive: How to use insert query like SQL

It is now possible to insert like ...READ MORE

answered Nov 5, 2018 in Big Data Hadoop by Omkar
• 69,220 points
885 views
–1 vote
1 answer

Beeline and Hive Query Editor in Embedded mode

Running Hive client tools with embedded servers ...READ MORE

answered Dec 31, 2018 in Big Data Hadoop by Omkar
• 69,220 points
1,441 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP