Pengcheng Xiong created HIVE-9008:
-------------------------------------

             Summary: primary table in union
                 Key: HIVE-9008
                 URL: https://issues.apache.org/jira/browse/HIVE-9008
             Project: Hive
          Issue Type: Sub-task
            Reporter: Pengcheng Xiong


Following http://dev.mysql.com/doc/refman/5.0/en/union.html

The column names from the first SELECT statement are used as the column names 
for the results returned. Selected columns listed in corresponding positions of 
each SELECT statement should have the same data type. (For example, the first 
column selected by the first statement should have the same type as the first 
column selected by the other statements.)

If the data types of corresponding SELECT columns do not match, the types and 
lengths of the columns in the UNION result take into account the values 
retrieved by all of the SELECT statements.

We can say

select A.id from A 
union 
select B.id from B
order by id

We can say

select A.id as a from A 
union 
select B.id from B
order by a

We can NOT say

select A.id as a from A 
union 
select B.id from B
order by A.id

ERROR 1054 (42S22): Unknown column 'A.id' in 'order clause'


We can NOT say

select A.id as a from A 
union 
select B.id from B
order by B.id

ERROR 1054 (42S22): Unknown column 'B.id' in 'order clause'


We can say

select A.id as a from A 
union 
(select B.id from B
order by B.id)




--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to