Reputation: 631
I have monthly Data in BigQuery but I want to create a yearly database, meaning combine the 12 subdatabase to 1.
How can it be done?
The structure is identical for all 12 databases in form:
Date, Name, Amount, Value, Type_of_Good
I thought JOIN might help me, but it is not the case.
Thanks
Upvotes: 8
Views: 10661
Reputation: 911
You can also use a UNION ALL
to concatenate tables with identical columns.
SELECT
Date, Name, Amount, Value, Type_of_Good
FROM
january
UNION ALL
SELECT
Date, Name, Amount, Value, Type_of_Good
FROM
february
And you can UNION ALL
for all the months you need.
Upvotes: 0
Reputation: 26617
Pentium10's suggestion works, but you might also consider two other options:
TABLE_QUERY()
(described here) which will allow you to construct a query that selects from multiple tables. TABLE_QUERY
or TABLE_DATE_RANGE
(although that functionality should be coming soon!). But a view would allow you to take the query suggested by Pentium10 and save it so that it looks like a single table.Upvotes: 7
Reputation: 207912
you can use the following syntax
SELECT Date, Name, Amount, Value, Type_of_Good
FROM
(select Date, Name, Amount, Value, Type_of_Good from january ...),
(select Date, Name, Amount, Value, Type_of_Good from february ...),
...
(select Date, Name, Amount, Value, Type_of_Good from december ...)
Upvotes: 8