Use below

SELECT
  col_a, col_b, el
FROM
  `table`,
UNNEST(array) as el
Answer from Mikhail Berlyant on Stack Overflow
🌐
Count
count.co › sql-resources › bigquery-standard-sql › unnest
UNNEST | BigQuery Standard SQL - Count.co
SELECT * FROM UNNEST([1, 2, 2, 5, NULL]) AS unnest_column WITH OFFSET AS `offset` SELECT * FROM UNNEST( ARRAY<STRUCT<fruit STRING , number INT64>>[ ('apples', 4), ('pears', 6), ('bananas', 2) ] ) AS simple_table; WITH fruit_baskets as ( SELECT * FROM UNNEST( ARRAY<STRUCT<fruit ARRAY<STRING>,basket ...
🌐
Google
docs.cloud.google.com › bigquery › work with arrays
Work with arrays | BigQuery | Google Cloud Documentation
The following example returns true if the array contains the number 2. SELECT 2 IN UNNEST([0, 1, 1, 2, 3, 5]) AS contains_value; /*----------------+ | contains_value | +----------------+ | true | +----------------*/ To return the rows of a table ...
Discussions

sql - Unnest array on bigQuery - Stack Overflow
My BigQuery table has some regular columns plus one array of structs. I'd like to run a query to flatten this structure, having one row for each element of the array, and duplicated values for the ... More on stackoverflow.com
🌐 stackoverflow.com
BigQuery UNNEST and Working with Arrays
How would you go about unnesting multiple array columns in one table without duplication, after unnesting the second column? More on reddit.com
🌐 r/bigquery
6
17
June 10, 2020
sql - How to unnest BigQuery nested records into multiple columns - Stack Overflow
I am trying to unnest the below table . Using the below unnest query to flatten the table SELECT id, name ,keyword FROM `project_id.dataset_id.table_id` ,unnest (`groups` ) as `groups` where id = More on stackoverflow.com
🌐 stackoverflow.com
Using UNNEST Function in BigQuery - Stack Overflow
I need help on how to use BigQuery UNNEST function. My query: I have table as shown in the image and I want to unnest the field "domains" (string type) currently separated by comma, so that I get ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Medium
medium.com › data-engineers-notes › unnesting-arrays-in-bigquery-c1b48d413ece
UNNESTING ARRAYS in BigQuery
April 15, 2024 - Probably the most common operation to do with them is to UNNEST them. The ARRAY is basically a set of rows inside one of the columns. In the example below each of the members have a list of activities they’re signed up for, together with the date they enrolled.
🌐
Yuichi Otsuka
yuichiotsuka.com › home › blog › bigquery unnest and working with arrays
BigQuery UNNEST and Working with Arrays - Yuichi Otsuka
June 10, 2024 - SELECT category, samples_individual FROM colors LEFT JOIN UNNEST(samples_array) AS samples_individual ; By adding the keyword LEFT JOIN, we get the following results. We now include the last row, with a NULL value for the column samples_individual.
🌐
Learn BigQuery!
scosco.github.io › learn-bigquery › foundation › subqueries.html
Subqueries: Arrays + UNNEST() | Learn BigQuery!
You can even think of your unnested array as a temporary table. But what about columns? A real table has a couple of columns, right? Introduce STRUCTs! SELECT * FROM UNNEST( [ STRUCT(12 as id, 'Hannah' as name), (13, 'Simone'), (14, 'Ada') ] ) BigQuery is semi-structured - that means the schema ...
🌐
Reddit
reddit.com › r/bigquery › bigquery unnest and working with arrays
r/bigquery on Reddit: BigQuery UNNEST and Working with Arrays
June 10, 2020 - If the two array columns are related by the order in each array, you can look at the WITH OFFSET keyword for UNNEST. More replies ... There are work arounds that let you use different data types for each column in an array, and ways to nest arrays inside arrays. By creating an array of structs you can have any data types you want for each column. And if you create an array of structs of arrays of structs you can nest them together. ... I was looking for more references to read about BigQuery and came here.
Find elsewhere
🌐
Datawise
datawise.dev › pay-attention-to-this-when-unnesting-in-bigquery
BigQuery UNNEST: LEFT JOIN vs Comma — Which Drops Rows?
3 weeks ago - Here's a common confusion that I encounter while working with ARRAYs in BigQuery. This can lead to wrong queries in some situations. Consider the following two snippets: FROM table, UNNEST(repeated_column) AS single_item
🌐
MarquinSmith
marquinsmith.com › home › data analysis › unnesting in bigquery – a guided introduction
UNNESTing in BigQuery – a guided introduction | MarquinSmith
October 5, 2023 - First create some data with an array field in and take a look · WITH toy_table AS ( SELECT "Marquin" AS user, ["bread", "grapes", "pringles", "pizza"] AS favourite_food UNION ALL SELECT "Jo", ["pizza", "banana"] UNION ALL SELECT "Sam", ["corn", "kiwi", "rice", 'jam', "chocolate"] UNION ALL SELECT "Peter", ["ice cream", "apple", "chocolate", "sausage", "pizza"] ) SELECT * FROM toy_table; UNNEST use case: We want to find out which food item is most commonly on people’s favourite food list.
🌐
DiveTeam
ken-williams.com › home › blog › how to flatten a bigquery table with unnest
How to Flatten a BigQuery Table with UNNEST - Ken Williams
May 10, 2020 - As an example, let’s say that ... example of a single row in your BigQuery table: event_name event_params keyvalue sharecontent_authorJen content_typepolitics · How the UNNEST operator Works UNNEST allows you to flatten ...
🌐
OneUptime
oneuptime.com › home › blog › how to flatten nested and repeated fields in bigquery with unnest
How to Flatten Nested and Repeated Fields in BigQuery with UNNEST
February 17, 2026 - -- Create a sample table with an array column CREATE TEMP TABLE products AS SELECT 'P001' AS product_id, 'Laptop' AS name, ['electronics', 'computers', 'portable'] AS tags UNION ALL SELECT 'P002', 'Headphones', ['electronics', 'audio', 'accessories'] UNION ALL SELECT 'P003', 'Desk', ['furniture', 'office']; -- Flatten the tags array into individual rows SELECT product_id, name, tag FROM products, UNNEST(tags) AS tag; -- Returns: -- P001 Laptop electronics -- P001 Laptop computers -- P001 Laptop portable -- P002 Headphones electronics -- P002 Headphones audio -- P002 Headphones accessories -- P003 Desk furniture -- P003 Desk office · The more common case is arrays of structured objects. This is how nested data typically appears in BigQuery.
Top answer
1 of 4
6

That's because the comma is a cross join - in combination with an unnested array it is a lateral cross join. You repeat the parent row for every row in the array.

One problem with pivoting arrays is that arrays can have a variable amount of rows, but a table must have a fixed amount of columns.

So you need a way to decide for a certain row that becomes a certain column.

E.g. with

SELECT 
  id,
  name,
  groups[ordinal(1)] as firstArrayEntry,
  groups[ordinal(2)] as secondArrayEntry,
  keyword
FROM `project_id.dataset_id.table_id`
unnest(groups)
where id = 204358

If your array had a key-value pair you could decide using the key. E.g.

SELECT 
  id,
  name,
  (select value from unnest(groups) where key='key1') as key1,
  keyword
FROM `project_id.dataset_id.table_id`
unnest(groups)
where id = 204358

But that doesn't seem to be the case with your table ...

A third option could be PIVOT in combination with your cross-join solution but this one has restrictions too: and I'm not sure how computation-heavy this is.

2 of 4
2

Consider below simple solution

select * from (
  select id, name, keyword, offset
  from `project_id.dataset_id.table_id`,
  unnest(`groups`) with offset 
) pivot (max(name) name for offset + 1 in (1, 2))      

if applied to sample data in your question - output is

Note , when you apply to your real case - you just need to know how many such name_NNN columns to expect and extend respectively list - for example for offset + 1 in (1, 2, 3, 4, 5)) if you expect 5 such columns

In case if for whatever reason you want improve this - use below where everything is built dynamically for you so you don't need to know in advance how many columns it will be in the output

execute immediate (select '''
select * from (
  select id, name, keyword, offset
  from `project_id.dataset_id.table_id`,
  unnest(`groups`) with offset 
) pivot (max(name) name for offset + 1 in (''' ||  string_agg('' || pos, ', ')  || '''))
'''
from (select pos from (
  select max(array_length(`groups`)) cnt
  from `project_id.dataset_id.table_id` 
  ), unnest(generate_array(1, cnt)) pos 
))
🌐
Towards Data Science
towardsdatascience.com › home › latest › bigquery unnest: how to work with nested data in bigquery
BigQuery UNNEST: How to work with nested data in BigQuery | Towards Data Science
January 24, 2025 - Event_date is a regular column, indicating which day the event occurred. Event_timestamp represents a derivative of Unix time to denote when the event took place. Tip: Event_timestamp ** in Firebase denotes the number of microseconds since 1 Jan 1970. To convert this into a BigQuery timestamp, you can use BigQuery’s timestamp_micro**s function: select timestamp_micros(event_timestamp) as event_ts, event_timestamp from blog_unnest.firebase_raw
🌐
Sheetgo
sheetgo.com › home › how to use unnest in bigquery
How to use unnest in BigQuery - Sheetgo
December 17, 2025 - In order to flatten nested data structures in BigQuery, we’ll use the UNNEST function. Here’s the UNNEST syntax: ... We’ll use the UNNEST function to break the “event_params” column down into separated rows.
🌐
Medium
medium.com › firebase-developers › how-to-use-select-from-unnest-to-analyze-multiple-parameters-in-bigquery-for-analytics-5838f7a004c2
How to use SELECT FROM UNNEST to analyze multiple parameters in BigQuery for Analytics | by Todd Kerpelman | Firebase Developers | Medium
April 9, 2020 - I know that’s a little hard to grok at first, so let’s take a look at our example. First thing I’m going to do is remove our original UNNEST statement and simplify our query to look at all our level complete events. SELECT event_name, event_timestamp, user_pseudo_id FROM `firebase-public-project.analytics_153293282.events_20181003` WHERE event_name = "level_complete_quickplay" Next, I’m going to ask BigQuery to SELECT the value.int_value column from our UNNESTed event_params array, where the key of the event parameter equals "value".
🌐
Medium
medium.com › data-engineers-notes › pay-attention-to-this-when-unnesting-in-bigquery-c06a1e911bef
Pay attention to this when UNNESTing in BigQuery | by Constantin Lungu | Data Engineer’s Notes | Medium
April 15, 2024 - Here’s a common confusion that I encounter while working with ARRAYs in BigQuery. This can lead to wrong queries in some situations. Consider the following two snippets: FROM table, UNNEST(repeated_column) AS single_item