Request a demo

BigQuery error · Query and syntax errors

Scalar subquery produced more than one element

A subquery used as a single value, in SELECT, WHERE or SET, returned two or more rows at run time. Make it return at most one row (aggregate it, filter on a unique key, add LIMIT 1 with ORDER BY), or use ARRAY(...) or a JOIN if several rows are expected.

Error reason invalidQuery · HTTP 400 · Checked against the Google Cloud docs in November 2026

The error message

Scalar subquery produced more than one element

Causes

Duplicate keys in the lookup table

A lookup such as (SELECT tier FROM customers c WHERE c.customer_id = o.customer_id) works while customer_id is unique and fails the day a duplicate is loaded. The query text didn't change; the data did.

A filter that isn't specific enough

Filtering on a non-unique column, such as a name or a date, matches several rows. With zero rows the subquery returns NULL, with one row its value, and with more it fails.

It is a runtime error

Unlike syntax and type errors, this one isn't found by a dry run or at analysis time. The message has no [line:column] position, because it is raised while the query runs.

How to fix it

1. Find the duplicated keys

Check which keys return more than one row before deciding how to pick one.

SELECT customer_id, COUNT(*) AS rows_per_key
FROM `project.dataset.customers`
GROUP BY customer_id
HAVING COUNT(*) > 1
ORDER BY rows_per_key DESC;

2. Pick one row deliberately

Order the subquery and keep one row, or aggregate it. Choose the rule that is correct for the data, such as the latest version.

WITH orders AS (SELECT 1 AS order_id, 'c1' AS customer_id),
customers AS (
  SELECT 'c1' AS customer_id, 'gold' AS tier, DATE '2026-11-01' AS valid_from UNION ALL
  SELECT 'c1', 'silver', DATE '2026-11-10'
)
SELECT
  o.order_id,
  (SELECT c.tier
   FROM customers AS c
   WHERE c.customer_id = o.customer_id
   ORDER BY c.valid_from DESC
   LIMIT 1) AS tier
FROM orders AS o;

3. Return all matches as an array

If several values are legitimate, ARRAY(...) returns them all in one value; an empty result gives an empty array.

WITH orders AS (SELECT 1 AS order_id),
items AS (
  SELECT 1 AS order_id, 'sku-1' AS sku UNION ALL
  SELECT 1, 'sku-2'
)
SELECT
  o.order_id,
  ARRAY(SELECT i.sku FROM items AS i WHERE i.order_id = o.order_id ORDER BY i.sku) AS skus
FROM orders AS o;

4. Use a JOIN for row-level lookups

Rewriting the lookup as a join on a deduplicated table is usually clearer and cheaper than a correlated subquery, and duplicates show up as extra rows instead of a failure.

How to prevent it

  • Test uniqueness of lookup keys (customer IDs, SKUs, mapping tables) in the pipeline that loads them, so a duplicate stops the load instead of every query that reads it.
  • Watch scheduled jobs that start failing with this error without a code change: it is a data quality signal, not a SQL bug.

FAQ

Is a query that fails with this error billed?

On-demand, no: queries that return an error aren't charged. Under editions, it is a runtime error, so the slot time the query used before it failed counts toward your reservation.

What does a scalar subquery return when there are no rows?

NULL. Only more than one row is an error, so a missing lookup is silent while a duplicate fails the query.

Is LIMIT 1 a good fix?

Only with an ORDER BY that picks the right row. LIMIT 1 alone returns an arbitrary row and hides the duplicate data that caused the error.

SQL reference

More query and syntax errors

All BigQuery error messages · What 50M daily events say about BigQuery failures

Stop finding BigQuery failures in Slack threads

Masthead watches every BigQuery job, dbt model, Dataform action and Airflow task from audit logs, groups failures into incidents and shows which tables and dashboards are affected. No access to your data and no added BigQuery cost.