Minus query seems to not work in HIVE.
Tried ex:
select x from abc
minus
select x from bcd ;
Am I doing this wrong or minus que
The above query might be easier to read if it was formatted slightly differently:
SELECT col1
FROM table1
WHERE NOT EXISTS (
SELECT col2
FROM table2
WHERE table1.col1 = table2.col2
)
This is a correlated sub-query. That is, the outer query is correlated to the inner (sub) query via the join contained in the subquery that references the outer query.
After joining tbl1 to tbl2, the result of that join (i.e. in this case, the list of col2 values that exist both in table1.col1 and table2.col2) the NOT Exists is applied to remove those values from the list of col1 values in Table1. The result is the list of col1 values in table1 that do not appear in table2.
Any "extra" values in Table2 that do not exist in table1 do not play a part in this query as they are removed by the inner join. This is fine, because the query is trying to return just those values in table1 that are not in table2 - extra values in table2 aren't in table1 in the first place - hence they are irrelevant.