union all的问题报错及解决办法

时间:2025-04-12 11:57:28

union all的问题报错及解决办法

union all的用法,其实不陌生的。union all上下的字段名要一致,字段数据类型要一致。但是满足上面两点后还是报错。

例如:
select a, b from t1
union all
select a,b from t2
上面的语句会报错,不知道为啥。

后面发现,原来是hive不支持顶层查询,换句话说,换成下面的代码就可以了

select
a,
b
from (
select a,b from t1
union all
select a,b from t2
) a