...
Code Block |
---|
SELECT key FROM src UNION SELECT key FROM src1 ORDER BY key LIMIT 10 |
When a specific column value is given in one or more SELECT statements (but not in all of them), the UNION may fail with an error message such as "FAILED: SemanticException 4:47 Schema of both sides of union should match." Column aliases should be used for such values, for example:
Code Block | ||
---|---|---|
| ||
INSERT OVERWRITE TABLE target_table
SELECT name, id, category FROM source_table_1
UNION ALL
SELECT name, id, "Category159" as category FROM source_table_2 |
Info | ||
---|---|---|
| ||
In Hive 0.12.0 and earlier releases, unions can only be used within a subquery such as "SELECT * FROM (select_statement UNION ALL select_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.) Before Hive 1.2.0, only UNION ALL (bag union) is supported. UNION (or UNION DISTINCT) is supported since Hive 1.2.0. (See HIVE-9039.) |
...