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. 用Eclipse编写运行Java程序

    1.选择一个空的文件夹,作为workspace工作空间,用来存放你以后用eclipse写的Java程序.(一个workspace可以放很多很多project项目) 2.新建java项目:File-&g ...

  2. NDK(15)在ndk代码中注册和注销native函数

    转自:  http://www.cnblogs.com/canphp/archive/2012/11/13/2768937.html C和C++注册native函数的方式大致上相同,下面给出具体的代码 ...

  3. asp.net读excle的数据类型不统一取出空值问题

    如果表格里某列全是数字或是字符没问题,但如果混合了全是数字和部分字符就会有部分读取为空连接EXCEL方式如下 string strConn = "Provider=Microsoft.Jet ...

  4. 手动配置gradle

    最近从github倒入项目,运行的特别慢gradle配置有问题,解决方法: 1.C:\android\demo\hellocharts-android-master\gradle\wrapper 目录 ...

  5. Tomcat 映射虚拟目录

    设置虚拟目录映射一般有两种用途: (1)把整个web应用映射到tomcat中: 如一个testapp的web应用的路径是/opt/testapp,则通过虚拟目录映射可以将其映射到tomcat(weba ...

  6. LeetCode Linked List Cycle 单链表环

    题意:给一个单链表,判断其是否出现环! 思路:搞两个指针,每次,一个走两步,另一个走一步.若有环,他们会相遇,若无环,走两步的指针必定会先遇到NULL. /** * Definition for si ...

  7. 物联网操作系统HelloX开发者入门指南

    HelloX开发者入门指南 HelloX是聚焦于物联网领域的操作系统开发项目,可以通过百度搜索"HelloX",获取详细信息.当前开发团队正在进一步招募中,欢迎您的了解和加入.如果 ...

  8. zollei的心动噪声探索性识别

    <Exploratory Identification of Cardiac Noise in fMRI Images> 这个方法,最特别的地方在于, 是从静息态的大脑数据中,抽取心动结构 ...

  9. FFmpeg 维基百科

    FFmpeg是一个自由软件,可以运行音频和视频多种格式的录影.转换.流功能[1],包含了libavcodec ─这是一个用于多个项目中音频和视频的解码器库,以及libavformat——一个音频与视频 ...

  10. java/python中获取当前系统时间,并与字符串相互转换格式,或者转化成秒数,天数等整数

    java转换成秒数 Date类有一个getTime()可以换回秒数,例如: public class DateToSecond { public static void main(String[] a ...