Subqueries in the FROM Clause

SELECT ... FROM (subquery) name ...
SELECT ... FROM (subquery) AS name ...   (Note: Only valid starting with Hive 0.13.0)

Hive supports subqueries only in the FROM clause (through Hive 0.12). The subquery has to be given a name because every table in a FROM clause must have a name. Columns in the subquery select list must have unique names. The columns in the subquery select list are available in the outer query just like columns of a table. The subquery can also be a query expression with UNION. Hive supports arbitrary levels of subqueries.

The optional keyword "AS" can be included before the subquery name in Hive 0.13.0 and later versions (HIVE-6519).

Example with simple subquery:

SELECT col
FROM (
  SELECT a+b AS col
  FROM t1
) t2

Example with subquery containing a UNION ALL:

SELECT t3.col
FROM (
  SELECT a+b AS col
  FROM t1
  UNION ALL
  SELECT c+d AS col
  FROM t2
) t3

Subqueries in the WHERE Clause

As of Hive 0.13 some types of subqueries are supported in the WHERE clause. Those are queries where the result of the query can be treated as a constant for IN and NOT IN statements (called uncorrelated subqueries because the subquery does not reference columns from the parent query):

SELECT *
FROM A
WHERE A.a IN (SELECT foo FROM B);

The other supported types are EXISTS and NOT EXISTS subqueries:

SELECT A
FROM T1
WHERE EXISTS (SELECT FROM T2 WHERE T1.X = T2.Y)

There are a few limitations:

  • These subqueries are only supported on the right-hand side of an expression.
  • IN/NOT IN subqueries may only select a single column.
  • EXISTS/NOT EXISTS must have one or more correlated predicates.
  • References to the parent query are only supported in the WHERE clause of the subquery.

[HIve - LanguageManual] Subqueries的更多相关文章

  1. [HIve - LanguageManual] Hive Operators and User-Defined Functions (UDFs)

    Hive Operators and User-Defined Functions (UDFs) Hive Operators and User-Defined Functions (UDFs) Bu ...

  2. [Hive - LanguageManual] DML: Load, Insert, Update, Delete

    LanguageManual DML Hive Data Manipulation Language Hive Data Manipulation Language Loading files int ...

  3. [Hive - LanguageManual ] Windowing and Analytics Functions (待)

    LanguageManual WindowingAndAnalytics     Skip to end of metadata   Added by Lefty Leverenz, last edi ...

  4. [HIve - LanguageManual] Joins

    Hive Joins Hive Joins Join Syntax Examples MapJoin Restrictions Join Optimization Predicate Pushdown ...

  5. [Hive - LanguageManual] Select base use

    Select Syntax WHERE Clause ALL and DISTINCT Clauses Partition Based Queries HAVING Clause LIMIT Clau ...

  6. [Hive - LanguageManual] Import/Export

    LanguageManual ImportExport     Skip to end of metadata   Added by Carl Steinbach, last edited by Le ...

  7. [Hive - LanguageManual] Alter Table/Partition/Column

    Alter Table/Partition/Column Alter Table Rename Table Alter Table Properties Alter Table Comment Add ...

  8. Hive LanguageManual DDL

    hive语法规则LanguageManual DDL SQL DML 和 DDL 数据操作语言 (DML) 和 数据定义语言 (DDL) 一.数据库 增删改都在文档里说得也很明白,不重复造车轮 二.表 ...

  9. [Hive - LanguageManual ] ]SQL Standard Based Hive Authorization

    Status of Hive Authorization before Hive 0.13 SQL Standards Based Hive Authorization (New in Hive 0. ...

随机推荐

  1. java:访问权限-protected实例

    在不同包,子类继承后可以使用父类的protect权限的属性或方法 父类: package com.tinyphp; public class Father { protected String nam ...

  2. 在Htmel中添加flash

    > >

  3. esriControlsMousePointer 控制鼠标指针

    axMapControl1.MousePointer = esriControlsMousePointer.esriPointerHourglass; 控制鼠标指针选项. 不变 值 描述 esriPo ...

  4. maven项目:Invalid bound statement

    在使用maven做mybatis项目时会遇到这个问题, org.apache.ibatis.binding.BindingException: Invalid bound statement (not ...

  5. Java API —— BigDecimal类

    1.BigDecimal类概述  由于在运算的时候,float类型和double很容易丢失精度,演示案例.所以,为了能精确的表示.计算浮点数,Java提供了BigDecimal 不可变的.任意精度的有 ...

  6. VS2015中快捷注释代码块

    注释ctrl+k   ctrl+c 反注释ctrl+k ctrl+u 需要注意的是第二个ctrl不能省略的

  7. 解析Android开发优化之:从代码角度进行优化的技巧

    下面我们就从几个方面来了解Android开发过程中的代码优化,需要的朋友参考下   通常我们写程序,都是在项目计划的压力下完成的,此时完成的代码可以完成具体业务逻辑,但是性能不一定是最优化的.一般来说 ...

  8. 循环中不要放入openSession()

    for(Shop s:list) { System.out.println(s.getName()); String sql="select shopId,sum(ele_bank+ele_ ...

  9. TCP协议的一些问题

    1 连接握手三次 解释1:已失效的连接请求报文段 情况下如下:client发出的第一个连接请求报文段并没有丢失,而是在某个网络结点长时间的滞留了,以致延误到连接释放以后的某个时间才到达server.本 ...

  10. shell 删除日志

    一般线上服务的日志都是采用回滚的防止,写一定数量的日志 或是有管理工具定期去转移老旧日志 前几天删除一个测试环境的日志,只保留两天的日志,结果把正在写的日志都给删掉了,不得不重启了服务,经过这一次的错 ...