Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HIVE check for data from table 1 which is absent in table 2

Tags:

sql

hive

I am looking to create a HIVE SQL query to find all the values from table 1 which ARE NOT present in table 2. I understand that I need to use a join however I cannot figure out how to implement it for this situation...

Thanks, James

for example:

Table1

url                  number
xe.com               5
google.com           2
ebay.co.uk           6

Table2

url                  visits
facebook.com         8
google.com           4
ebay.co.uk           15

So for example the query should return all values from Table1 which are present in Table2, i.e.

url                  number         visits
google.com           2              4
ebay.co.uk           6              15
like image 409
user2160581 Avatar asked Mar 12 '13 11:03

user2160581


People also ask

How do I select data from one table is not in another table?

We can get the records in one table that doesn't exist in another table by using NOT IN or NOT EXISTS with the subqueries including the other table in the subqueries.

When you want to return only those rows of data for which the key is present in both the tables which join would you use?

FULL JOIN. A FULL JOIN or FULL OUTER JOIN is essentially a combination of LEFT JOIN and RIGHT JOIN . This type of join contains all of the rows from both of the tables. Where the join condition is met, the rows of the two tables are joined, just as in the previous examples we've seen.


1 Answers

A LEFT JOIN will return all rows from Table1 regardless of whether or not there's a match. In the case that there isn't a match the columns from Table2 will have the value NULL - these are the rows you want:

SELECT Table1.url, Table1.number
FROM Table1
LEFT OUTER JOIN Table2 ON Table1.url = Table2.url
WHERE Table2.url IS NULL
like image 192
Anthony Grist Avatar answered Sep 19 '22 15:09

Anthony Grist