[HIve - LanguageManual] Union
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的更多相关文章
- [HIve - LanguageManual] Hive Operators and User-Defined Functions (UDFs)
Hive Operators and User-Defined Functions (UDFs) Hive Operators and User-Defined Functions (UDFs) Bu ...
- [Hive - LanguageManual] DML: Load, Insert, Update, Delete
LanguageManual DML Hive Data Manipulation Language Hive Data Manipulation Language Loading files int ...
- hive 中 union all
hive 中的union all是不能在sql语句的第一层使用的,否则会报 Top level UNION is not supported currently 错误: 例如如下的方式: select ...
- [Hive - LanguageManual ] Windowing and Analytics Functions (待)
LanguageManual WindowingAndAnalytics Skip to end of metadata Added by Lefty Leverenz, last edi ...
- [HIve - LanguageManual] Subqueries
Subqueries in the FROM Clause Subqueries in the WHERE Clause Subqueries in the FROM Clause SELECT .. ...
- [HIve - LanguageManual] Joins
Hive Joins Hive Joins Join Syntax Examples MapJoin Restrictions Join Optimization Predicate Pushdown ...
- [Hive - LanguageManual] Select base use
Select Syntax WHERE Clause ALL and DISTINCT Clauses Partition Based Queries HAVING Clause LIMIT Clau ...
- [Hive - LanguageManual] Import/Export
LanguageManual ImportExport Skip to end of metadata Added by Carl Steinbach, last edited by Le ...
- [Hive - LanguageManual] Alter Table/Partition/Column
Alter Table/Partition/Column Alter Table Rename Table Alter Table Properties Alter Table Comment Add ...
随机推荐
- 每用户订阅上的所有者 SID 不存在 (异常来自 HRESULT:0x80040207)
出现这个问题是因为pQueryFilter.WhereClause = "RoomNumber=" +cmbFromPoint.SelectedItem;中的cmbFromPoin ...
- iOS xcuserdata
说明: project.xcworkspace说明:is a directory of files describing the workspace or projects. Althou ...
- dubbo-admin管理平台搭建
参考:http://blog.csdn.net/u013142781/article/details/50396621 一.前言 dubbo的使用,其实只需要有注册中心,消费者,提供者这三个就可以使用 ...
- 在C#中实现Python的分片技术
在C#中实现Python的分片技术 前言 之前在学习Python的时候发现Python中的分片技术超好玩的,本人也是正则表达式热爱狂,平时用C#比较多,所以决定把Python中的分片技术在C#中实现, ...
- 内存泄露了么: Handlers & Inner Classes
看到一篇关于handler和匿名类关于内存泄露的文章,觉得不错,充分发挥拿来主义,先放这儿看着! From:http://www.androiddesignpatterns.com/2013/01/i ...
- JNI读取assets资源文件
源自:http://www.rosoo.net/a/201112/15459.html assets目录底下的文件会被打包到一个apk文件里,这些资源在安装时他们并没被解压,使用时是直接从apk中读取 ...
- sql partition by 的使用
select a.bs_sn, a.bs_bd_no, a.bs_bk_code, a.bs_kind_no, a.bs_flag, b.det_flag, c.bp_in_no, c.bp_name ...
- javascript算法汇总(持续更新中)
1. 线性查找 <!doctype html> <html lang="en"> <head> <meta charset="U ...
- .net 程序员成长路线图?
https://www.zhihu.com/question/25474641 得看赵四本, @赵劼 推荐的. CLR via C# .net Essentials C# in Depth Frame ...
- [LeetCode#267] Palindrome Permutation II
Problem: Given a string s, return all the palindromic permutations (without duplicates) of it. Retur ...