Hi Joseph,
BigQuery supports multiple joins, but a single SELECT statement can only contain one JOIN clause, one (or both) of whose clauses can themselves be SELECT statements. (It's also worth noting that while we don't support 'SELECT * FROM ...' at top-level, we
do support it in subselects.) This means that you have to manually insert an additional SELECT for each additional JOIN. (Doing this automatically is on our todo list, but hasn't happened yet.) It looks like that example from our docs needs to get cleaned up; there are several ways to skin this cat, but I think the most natural would be:
SELECT joined.purchases.amount, products.name, joined.users.email_address
FROM
(SELECT *
FROM PurchaseData AS purchases
JOIN UserData AS users
ON purchases.user_id = users.user_id) AS joined
JOIN ProductData AS products
ON joined.purchases.product_id = products.product_id
You'll notice that I've basically just rewritten the first JOIN into a SELECT, and added one extra layer for the names of the joined tables. Alternately, you could explicitly select the fields you needed:
SELECT purchases.amount, products.name, purchases.email_address
FROM
(SELECT purchases.amount AS amount,
users.email_address AS email_address,
purchases.product_id AS product_id
FROM PurchaseData AS purchases
JOIN UserData AS users
ON purchases.user_id = users.user_id) AS purchases
JOIN ProductData AS products
ON purchases.product_id = products.product_id
Does that make sense? Feel free to reply back if you're curious about how to do this in your case.
Thanks for pointing out this example in the docs -- we'll get it fixed soon!
--
-cc