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
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With