Skip to content
Advertisement

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 ?

Advertisement

Answer

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;
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement