Hive Union (translated from hive wiki)

Source: Internet
Author: User

Union syntax

 
Select_statement Union all select_statement...

Union is used to combine the result sets of multiple select statements into an independent result set. Currently, only union all (BAG Union) is supported ). Duplicate rows are not eliminated. The number and name of columns returned by each select statement must be the same. Otherwise, a syntax error is thrown.

 

If some extra processing is required for the Union result, the entire statement can be embedded in the from clause, as shown below:

 
Select *From (select_statement Union all select_statement) unionresult

 

For example, if we assume there are two different tables to track which user publishes a video and which user has posted a comment, and the following query results are used together with all user tables, creates a single comment stream for all video publishing and comment publishing events.

Select U.ID, Actions.DateFrom (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)

Translation from https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Union

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.