Request a demo

BigQuery error · Query and syntax errors

SELECT list expression references column which is neither grouped nor aggregated

The query has GROUP BY or an aggregate function, and a selected column is neither in GROUP BY nor inside an aggregate, so BigQuery can't pick one value per group. Add the column to GROUP BY, wrap it in an aggregate such as ANY_VALUE or MAX, or compute it in a separate step.

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

The error message

SELECT list expression references column <column> which is neither grouped nor aggregated at [<line>:<column>]

Causes

A column left out of GROUP BY

SELECT customer_id, region, SUM(amount) FROM orders GROUP BY customer_id fails on region. GoogleSQL doesn't guess a value even if region is the same for every row of a customer.

Habits from MySQL

MySQL without ONLY_FULL_GROUP_BY returns an arbitrary value for such columns. BigQuery, like PostgreSQL and Snowflake, rejects the query instead.

The same rule in other clauses

HAVING, ORDER BY and QUALIFY follow the same rule and produce HAVING clause expression references column ..., ORDER BY clause expression references column ... or QUALIFY clause expression references column .... SELECT * in a grouped query reports Star expansion expression references column ....

An aggregate mixed with plain columns by accident

Adding a COUNT(*) or SUM() to a query that had no GROUP BY turns the whole query into one group, so every other selected column now fails.

How to fix it

1. Add the column to GROUP BY

If the column defines the groups, group by it. GROUP BY can use the select alias or position.

WITH orders AS (
  SELECT 'c1' AS customer_id, 'EU' AS region, 10.0 AS amount UNION ALL
  SELECT 'c1', 'EU', 5.0 UNION ALL
  SELECT 'c2', 'US', 7.5
)
SELECT customer_id, region, SUM(amount) AS revenue
FROM orders
GROUP BY customer_id, region;

2. Aggregate the column

Use ANY_VALUE when the column has one value per group anyway (an attribute of the key), or MAX, MIN, ARRAY_AGG when it varies and you need a specific one.

WITH orders AS (
  SELECT 'c1' AS customer_id, 'EU' AS region, 10.0 AS amount UNION ALL
  SELECT 'c1', 'EU', 5.0
)
SELECT customer_id, ANY_VALUE(region) AS region, SUM(amount) AS revenue
FROM orders
GROUP BY customer_id;

3. Use a window function to keep row detail

If you need each row together with a group total, compute the total with OVER (PARTITION BY ...) instead of GROUP BY.

WITH orders AS (
  SELECT 'c1' AS customer_id, 1 AS order_id, 10.0 AS amount UNION ALL
  SELECT 'c1', 2, 5.0
)
SELECT customer_id, order_id, amount,
  SUM(amount) OVER (PARTITION BY customer_id) AS customer_total
FROM orders;

How to prevent it

  • Join descriptive attributes after aggregating: group the fact table by key first, then join the dimension table to the small result. It is also cheaper, because the join handles fewer rows.
  • Dry-run reports and dbt models in CI; the error is caught for free before the scheduled run.

FAQ

Is ANY_VALUE safe to use?

It returns the value from some row of the group, so it is correct only when the column has one value per group, such as a customer's region grouped by customer ID. If values differ, use MIN, MAX or a rule that picks the right row.

Is a query that fails with this error billed?

No. It fails during analysis, before reading data, so it costs nothing on-demand and uses no slots under editions.

Does BigQuery support GROUP BY ALL?

GoogleSQL supports GROUP BY ALL, which groups by every SELECT item that isn't an aggregate. It avoids this error but also groups by any column you forgot to aggregate, so check the result's grain.

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.