Reputation: 664
I have a bigquery table containing a field candidate of array type. How can I query distinct rows from this table?
In this case my query should return just the first row.
Upvotes: 2
Views: 1840
Reputation: 7298
Something like:
select split(combed, ".") as candidate from (
select distinct array_to_string(candidate, ".") as combed
from `dataset.table`
)
Upvotes: 0
Reputation: 173190
I think below is the simplest way and works for any types and length , etc.
#standardSQL
SELECT ANY_VALUE(candidate) candidate
FROM `project.dataset.table`
GROUP BY FORMAT('%T', candidate)
Previously I used to use TO_JSON_STRING() for this - but recently realized that FORMAT() fits best for most cases like this
Upvotes: 4