Search code examples
sqlhiveunionhiveqlhive-query

Hive: Cant perform union query with limit


I am trying to run a union all query in hive

select * from tabName where col1='val1' and col2 = 'val2' limit 10 union all select * from tabName where col1='val1' and col2 = 'val3' limit 10;

but i get

FAILED: ParseException line 1:105 missing EOF at 'union' near '10'

I also tried

( select * from tabName where col1='val1' and col2 = 'val2' limit 10 ) as a union all ( select * from tabName where col1='val1' and col2 = 'val3' limit 10 ) as b;

but i got

FAILED: ParseException line 1:109 missing EOF at 'as' near ')'

what am i doing wrong ?


Solution

  • Use select from subquery:

    select * from
    ( select * from tabName where col1='val1' and col2 = 'val2' limit 10 ) a 
    union all 
    select * from
    ( select * from tabName where col1='val1' and col2 = 'val3' limit 10 ) b;