user3690992
user3690992

Reputation: 41

Union ALL multiple query Google BigQuery

I have three queries with the same column count and structure, does Google BigQuery support union all? I know it supports union but I need it to merge the result of the query into one result.

I have tried:

SELECT * 
FROM 
(SELECT a.a AS a, a.b AS b, d.c AS c FROM table_a a JOIN table_d d on d.a = a.a),
(SELECT c.a AS a, c.b AS b, d.c AS c FROM table_c c JOIN table_d d on d.a = ca.a),
(SELECT b.a AS a, b.b AS b, d.c AS c FROM table_b b JOIN table_d d on d.a = b.a)

I get the following error:

Union results in ambiguous schema [d.c] is ambiguous and is aliasing multiple fields

Thanks For your help.

Upvotes: 2

Views: 3577

Answers (1)

Su Yin He
Su Yin He

Reputation: 21

Must you know if the data are come from table a, b or c? If you don't need to know, you can try the following query:

select *
from
(select a, b
from table_a, table_b, table_c) as a
join
(select a, c
from table_d) as d 
on a.a = d.a

Upvotes: 1

Related Questions