Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Array_agg containing distinct structs

I'm attempting to create an array with distinct struct as values for a column, something like so

select array_agg(distinct struct(field_a, field_b)) as c FROM tables ...

is that possible?

like image 389
Joyce Avatar asked Dec 29 '25 19:12

Joyce


1 Answers

#standardSQL
SELECT ARRAY_AGG(STRUCT(field_a, field_b)) c 
FROM (
  SELECT DISTINCT field_a, field_b
  FROM `project.dataset.table`
)
like image 187
Mikhail Berlyant Avatar answered Dec 31 '25 07:12

Mikhail Berlyant



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!