2

I have a bigquery table containing a field candidate of array type. How can I query distinct rows from this table?

enter image description here

In this case my query should return just the first row.

2 Answers 2

4

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

Sign up to request clarification or add additional context in comments.

2 Comments

exactly! :o) depends on case it is either %T or %t to be used for the best result :o)
0

Something like:

select split(combed, ".") as candidate from (
   select distinct array_to_string(candidate, ".") as combed 
   from `dataset.table`
)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.