Below is for BigQuery Standard SQL

#standardSQL
SELECT * EXCEPT(status, locale, pos1, pos2), status, locale  
FROM `project.dataset.table`,
UNNEST(status) status WITH OFFSET pos1,
UNNEST(locale) locale WITH OFFSET pos2
WHERE pos1 = pos2
Answer from Mikhail Berlyant on Stack Overflow
🌐
Count
count.co › sql-resources › bigquery-standard-sql › unnest
UNNEST | BigQuery Standard SQL - Count.co
This will create multiple rows for each element of your array but you can then filter it down. SELECT * FROM UNNEST([1, 2, 2, 5, NULL]) AS unnest_column
🌐
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 ...
Discussions

Advanced UNNEST Across Multiple Array Columns in BigQuery - Stack Overflow
question about UNNEST. I have this table: I want to unnest based on the status and locale arrays but the result table still needs to have 7 rows, NOT 14. I want to unnest those "array pairs", not ... More on stackoverflow.com
🌐 stackoverflow.com
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
UNNEST Multiple Fields From the same Table - BigQuery - Stack Overflow
I would like to UNNEST both Info2 and Info3 for the following query. How can I do this for the same table in BigQuery. Info3 also has a condition similar to info2. Thanks! ID | startDate | endDa... More on stackoverflow.com
🌐 stackoverflow.com
How to refer those columns
Thanks for your submission to r/BigQuery . Did you know that effective July 1st, 2023, Reddit will enact a policy that will make third party reddit apps like Apollo, Reddit is Fun, Boost, and others too expensive to run? On this day, users will login to find that their primary method for interacting with reddit will simply cease to work unless something changes regarding reddit's new API usage policy. Concerned users should take a look at r/modcoord . I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/bigquery
7
3
November 29, 2023
🌐
Google
docs.cloud.google.com › bigquery › work with arrays
Work with arrays | BigQuery | Google Cloud Documentation
SELECT * FROM UNNEST(['foo', 'bar', ... of the other columns in each row, use a correlated INNER JOIN to join the table containing the ARRAY column to the UNNEST output of that ARRAY column....
🌐
Medium
medium.com › data-engineers-notes › unnesting-arrays-in-bigquery-c1b48d413ece
UNNESTING ARRAYS in BigQuery
April 15, 2024 - If we want to perform operations (say find out what was the earliest enrollment date, or count the distinct activities that the members are enrolled in), we’d need to unpack these rows by UNNESTing the ARRAY where activities are stored it. This will bring us from 1 (table) row per member to 1 row per each activity a member is enrolled in. Pay attention here to how we’re joining the UNNEST — this will determine if we keep or not the members that don’t have any activities. LEFT JOIN = keep them CROSS JOIN / , (also a cross join) / INNER JOIN = exclude them · Do remember to give the UNNESTed items a proper logical name i.e.
🌐
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 - UNNEST is the essential tool for working with nested and repeated fields in BigQuery. Whether you are flattening simple arrays, navigating multi-level nested structs, or working with complex exports like Google Analytics data, UNNEST lets you bring nested data into a row-oriented format for analysis. Remember to use LEFT JOIN when you need to preserve rows with empty arrays, and be mindful of the row multiplication effect when unnesting multiple arrays.
🌐
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 needs to be consistent.
Find elsewhere
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 
))
🌐
Yuichi Otsuka
yuichiotsuka.com › home › blog › bigquery unnest and working with arrays
BigQuery UNNEST and Working with Arrays - Yuichi Otsuka
June 10, 2024 - When we use the UNNEST function on a column in BigQuery, all the rows under that column is flattened all at once. Currently, the UNNEST function does not accept multiple arrays as parameters.
🌐
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 ... UNNEST operator Works UNNEST allows you to flatten the “event_params” column so that each item in the array creates a single row in the table with two new columns: “event_params.key” ...
🌐
Medium
simonwrigley.medium.com › flattening-multiple-arrays-in-google-bigquery-e1f9e4af71e2
Flattening Multiple Arrays in Google BigQuery - Simon Wrigley - Medium
July 16, 2024 - When it comes to unnesting multiple array columns however, BigQuery offers comma cross join syntax which is much simpler and easier to read where you simply follow the initial SELECT statement with a comma separated list of UNNEST statements ...
🌐
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 - Again, we use the BigQuery UNNEST function to achieve this. The basic approach is to: ... Reconstruct the structure using the ARRAY and STRUCT datatypes accordingly.
🌐
Sheetgo
blog.sheetgo.com › home › how to use unnest in bigquery
How to use unnest in BigQuery - Sheetgo
December 17, 2025 - The UNNEST function in BigQuery is used to flatten nested or repeated data structures into separate rows. What it does is take as input a column with a nested data type like an ARRAY, and expand the nested or repeated elements into multiple ...
🌐
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
🌐
Google Cloud
cloud.google.com › bigquery › query syntax
Query syntax | BigQuery | Google Cloud Documentation
The UNNEST operator takes an array and returns a table with one row for each element in the array. The output of UNNEST is one value table column. For these ARRAY element types, SELECT * against the value table column returns multiple columns:
🌐
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.