Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merging tables in Bigquery

I have 2 web sites and i am sending all the GA data into Big Query. Since Big Query would create different tables for each site, i would like to merge them into one. Also i would like to create a record to indicate the site's name so that site A and Site B data won't be mixed.

Is this possible? I have tried union, it works fine but just the i am not able to differentiate the data between site a and site b.

Appreciated Thanks

like image 803
sam123 Avatar asked Oct 17 '25 14:10

sam123


1 Answers

Assuming schemas identical:

SELECT * FROM 
(SELECT *, 'siteA' AS site FROM TableA),
(SELECT *, 'siteB' AS site FROM TableB)

you should use [ ] when using fully qualified table name - project:dataset.table

SELECT * FROM 
(SELECT *, 'siteA' AS site FROM [ga:123.ga_sessions_20160502]), 
(SELECT *, 'siteB' AS site FROM [ga:456.ga_sessions_20160501])
like image 145
Mikhail Berlyant Avatar answered Oct 21 '25 23:10

Mikhail Berlyant



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!