how to write subquery and use “In” Clause in Hive

后端 未结 7 1783
滥情空心
滥情空心 2021-01-31 19:49

How can I use In clause in Hive I want to write something like this in Hive select x from y where y.z in (select distinct z from y) order by x; But I am not finding any way o

相关标签:
7条回答
  • 2021-01-31 20:39

    You can use semi join(https://cwiki.apache.org/Hive/languagemanual-joins.html):

    LEFT SEMI JOIN implements the correlated IN/EXISTS subquery semantics in an efficient way. Since Hive currently does not support IN/EXISTS subqueries, you can rewrite your queries using LEFT SEMI JOIN. The restrictions of using LEFT SEMI JOIN is that the right-hand-side table should only be referenced in the join condition (ON-clause), but not in WHERE- or SELECT-clauses etc.

    SELECT a.key, a.value
      FROM a
      WHERE a.key in
       (SELECT b.key
        FROM B);
    

    can be rewritten to:

       SELECT a.key, a.val
       FROM a LEFT SEMI JOIN b on (a.key = b.key)
    
    0 讨论(0)
提交回复
热议问题