Dylan Russell
Dylan Russell

Reputation: 1098

BigQuery SQL Best practice to join multiple tables/subqueries by common variable

What is the most efficient (or best practice) way of joining multiple tables by a common variable in BigQuery SQL?

To date, I have been utilizing queries similar to:

select * from

    (select * from

        (select * from (
          subquery1
        ) 
        where criteria is true
        inner join table1 using(var)
    )
    where criteria is true
    inner join table2 using(var)
)

inner join table3 using(var)

Upvotes: 0

Views: 297

Answers (1)

Mikhail Berlyant
Mikhail Berlyant

Reputation: 172994

Consider below option

select * from (
  subquery1
) 
join table1 using(var)
join table2 using(var)
join table3 using(var) 
where all_criterias is true

Also check out https://cloud.google.com/bigquery/docs/release-notes#August_19_2020

Upvotes: 1

Related Questions