Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BigQuery JOINs between tables in different projects

I have datasets in two distinct projects.

I want to perform join of one table from a dataset in the first project to table in a dataset in the second project.

Can you provide an example of such a query?

like image 314
Sunil Garg Avatar asked Jun 13 '15 17:06

Sunil Garg


People also ask

What is cross join in BigQuery?

Cross joins are queries where each row from the first table is joined to every row in the second table (there are non-unique keys on both sides). The worst case output is the number of rows in the left table multiplied by the number of rows in the right table. In extreme cases, the query might not finish.

How do you join tables in BigQuery?

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.


1 Answers

Yes, you certainly can. You need to qualify the table name with project name, i.e. projectname:dataset.table Here is an example of my joining one of my tables against table in publicdata project:

select sum(a.is_male)
from
(select is_male, year from [publicdata:samples.natality]) a
inner join
(select year from [moshap.my_years]) b
on a.year = b.year

Update: The syntax above is for Legacy SQL, with Standard SQL it becomes projectname.dataset.table, i.e.

select sum(a.is_male)
from
(select is_male, year from publicdata.samples.natality) a
inner join
(select year from moshap.my_years) b
on a.year = b.year
like image 74
Mosha Pasumansky Avatar answered Sep 20 '22 19:09

Mosha Pasumansky