BigQuery does not seem to have support for UNION yet: https://developers.google.com/bigquery/docs/query-reference
(I don't mean unioning tables together for the source. It has that.)
Is it coming soon?
There are two main ways to unite results with UNION in BigQuery which is: Comma-Delimited UNIONS in Legacy SQL and Standard SQL. Comma-Delimited UNIONS in Legacy SQL: With this method, merging data is very easy. All you need is a comma-separated list of the many tables included inside the FROM clause.
The SQL UNION OperatorThe UNION operator is used to combine the result-set of two or more SELECT statements.
Click the join and choose Delete. Create a new join by dragging the column name from the second table to the corresponding column name in the first table. Click Execute SQL. If a preview of your data appears in the Sample Preview pane, the join was successfully created.
If you want UNION so that you can combine query results, you can use subselects in BigQuery:
SELECT foo, bar FROM (SELECT integer(id) AS foo, string(title) AS bar FROM publicdata:samples.wikipedia limit 10), (SELECT integer(year) AS foo, string(state) AS bar FROM publicdata:samples.natality limit 10);
This is almost exactly equivalent to the SQL
SELECT id AS foo, title AS bar FROM publicdata:samples.wikipedia limit 10 UNION ALL SELECT year AS foo, state AS bar FROM publicdata:samples.natality limit 10;
(note that if want SQL UNION and not UNION ALL this won't work)
Alternately, you could run two queries and append the result.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With