Union Syntax

select_statement UNION ALL select_statement UNION ALL select_statement ...

UNION is used to combine the result from multiple SELECT statements into a single result set. Hive currently only supports UNION ALL (bag union), in which duplicates are not eliminated. The number and names of columns returned by each select_statement have to be the same. Otherwise, a schema error is thrown.

If some additional processing has to be done on the result of the UNION, the entire statement expression can be embedded in a FROM clause like below:

SELECT *
FROM (
  select_statement
  UNION ALL
  select_statement
) unionResult

For example, if we suppose there are two different tables that track which user has published a video and which user has published a comment, the following query joins the results of a UNION ALL with the user table to create a single annotated stream for all the video publishing and comment publishing events:

SELECT u.id, actions.date
FROM (
    SELECT av.uid AS uid
    FROM action_video av
    WHERE av.date = '2008-06-03'
    UNION ALL
    SELECT ac.uid AS uid
    FROM action_comment ac
    WHERE ac.date = '2008-06-03'
 ) actions JOIN users u ON (u.id = actions.uid)

Unions can be used in views, inserts, and CTAS (create table as select) statements. A query can contain multiple UNION ALL clauses, as shown in the syntax above.

Version information

Icon

In Hive 0.12.0 and earlier releases, unions can only be used within a subquery such as "SELECT * FROM (select_statement UNION ALLselect_statement UNION ALL ...) unionResult".

As of Hive 0.13.0, unions can also be used in a top-level query: "select_statement UNION ALL select_statement UNION ALL ...". (See HIVE-6189.)

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

  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 中 union all

    hive 中的union all是不能在sql语句的第一层使用的,否则会报 Top level UNION is not supported currently 错误: 例如如下的方式: select ...

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

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

  5. [HIve - LanguageManual] Subqueries

    Subqueries in the FROM Clause Subqueries in the WHERE Clause Subqueries in the FROM Clause SELECT .. ...

  6. [HIve - LanguageManual] Joins

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

  7. [Hive - LanguageManual] Select base use

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

  8. [Hive - LanguageManual] Import/Export

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

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

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

随机推荐

  1. OpenCV源码阅读(2)---matx.h---函数的内联实现

    外部矩阵计算函数 namespace internal { template<typename _Tp, int m> struct Matx_DetOp { double operato ...

  2. Spring 操作数据库

    试了一下spring的JdbcTemplate觉得很好用.首先增加一个连接到mysql数据库的dataSource <bean id="dataSource2" class= ...

  3. 最受欢迎的ASP.NET的CMS下载

    1. Umbraco 项目地址 下载 Umbraco是一个开放源码的CMS内容管理系统,基于asp.net建立,使用mssql进行存储数据.使用Umbraco,设计师能创造出有效的XHTML标记模板和 ...

  4. 在Hadoop伪分布式模式下安装Hive(derby,mysql)

    我的Hadoop版本是1.2.0,mysql版本是5.6.12. 先介绍一下嵌入式derby模式: 1.下载/解压 在hive官网上选择要下载的版本,我选择的版本是hive-0.10.0. 下载好解压 ...

  5. UDP protocol

    Characteristics of the UDP protocol The UDP protocol (User Datagram Protocol) is a connectionless or ...

  6. Windows 7更改SVN账户密码

    首先说明下我的系统是Windows7 今天更改了SVN账号和密码,然后想要更改一下Eclipse的SVN登录用户名和密码 但是网上找了一大推说什么客户端的,靠净扯淡. 本人亲测最有效的方法是删除C盘下 ...

  7. Myeclipse多行注释快捷键及其他快捷键

    当时我看到struts2讲解视频的时候,讲解员居然能一下子注释掉好几行代码,而且注释的很整齐,然我大吃一惊,上网搜了下Myeclipse的快捷键还真多 选择你要注释的那一行或多行代码,按Ctrl+/即 ...

  8. POJ 2065 SETI (高斯消元 取模)

    题目链接 题意: 输入一个素数p和一个字符串s(只包含小写字母和‘*’),字符串中每个字符对应一个数字,'*'对应0,‘a’对应1,‘b’对应2.... 例如str[] = "abc&quo ...

  9. Unique Encryption Keys (思维题 预处理)

    题目 题意:给m个数字, q次询问, 询问b到e之间如果有重复数字就输出, 没有就输出OK 思路:用f[i]数组 记录从i开始向后最近的有重复数字的 位置, 如 1 3 2 2, 则f[1] = 4; ...

  10. 函数fil_io

    /********************************************************************//** Reads or writes data. This ...