BigQuery error · Query and syntax errors
Correlated subqueries that reference other tables are not supported
A subquery reads another table and refers to a column of the outer query, and BigQuery couldn't rewrite it into a join. Rewrite it yourself: a JOIN with the condition, a pre-aggregated or deduplicated table joined on the key, or QUALIFY to pick one row per key.
The error message
Correlated subqueries that reference other tables are not supported unless they can be de-correlated, such as by transforming them into an efficient JOIN.
Causes
The correlated subquery can't be turned into a join
BigQuery evaluates correlated subqueries by rewriting them as joins. Some shapes, often a correlated subquery over another table that also uses ORDER BY with LIMIT, EXISTS, NOT EXISTS or IN, or that sits in an unusual place in the query, can't be rewritten and fail with this error.
As-of lookups written row by row
"For each order, find the price valid at the order date" written as a subquery per row is a common trigger, especially with a range condition such as p.valid_from <= o.order_date in the correlation.
SQL ported from row-by-row engines
PostgreSQL and SQL Server run correlated subqueries as nested loops. BigQuery doesn't execute them that way, so queries that work there can fail here.
How to fix it
1. Rewrite as a JOIN with QUALIFY
Join on the key, keep the range condition in the join, and keep the best match per outer row with QUALIFY.
WITH orders AS (
SELECT 1 AS order_id, 'c1' AS customer_id, DATE '2026-11-10' AS order_date
),
tiers AS (
SELECT 'c1' AS customer_id, DATE '2026-11-01' AS valid_from, 'gold' AS tier UNION ALL
SELECT 'c1', DATE '2026-11-05', 'silver'
)
SELECT o.order_id, t.tier
FROM orders AS o
LEFT JOIN tiers AS t
ON t.customer_id = o.customer_id
AND t.valid_from <= o.order_date
WHERE TRUE
QUALIFY ROW_NUMBER() OVER (PARTITION BY o.order_id ORDER BY t.valid_from DESC) = 1;2. Replace EXISTS with a semi-join on a deduplicated key list
Compute the matching keys once and join to them.
WITH customers AS (
SELECT 'c1' AS customer_id UNION ALL SELECT 'c2'
),
refunds AS (
SELECT 'c1' AS customer_id, 20.0 AS amount
),
refunded AS (
SELECT DISTINCT customer_id FROM refunds WHERE amount > 0
)
SELECT c.customer_id
FROM customers AS c
JOIN refunded AS r USING (customer_id);3. Materialize the inner side in a temporary table
In a multi-statement query, aggregate the inner table into a temp table first, then join or reference it. Google's troubleshooting guide also suggests removing ORDER BY, LIMIT, EXISTS, NOT EXISTS or IN from the subquery, or using a CROSS JOIN.
How to prevent it
- Write lookups as joins from the start; they are easier to read and BigQuery can plan them well.
- Dry-run queries migrated from row-by-row databases in CI: this error is found at analysis time, for free.
FAQ
Does BigQuery support correlated subqueries at all?
Yes, many work, such as EXISTS or scalar subqueries with an equality on a key, because BigQuery can rewrite them as joins. The error appears only for the shapes it can't rewrite.
Is a query that fails with this error billed?
No. It fails while BigQuery plans the query, before reading data, so it costs nothing on-demand and uses no slots under editions.
Why does the same subquery work on a CTE but not on a table?
The message is about subqueries that reference other tables. When the inner side is small inline data, BigQuery can often rewrite or evaluate it differently, so tests on sample CTEs can pass while the query on real tables fails.
Related
SQL reference
More query and syntax errors
All BigQuery error messages · What 50M daily events say about BigQuery failures
