30 Oct 19 · victor · #Bigquery ·   Bookmark  

×

How to Select Distinct values in Google Bigquery ?

Problem:

How to run a query to find distinct values:

SELECT DISTINCT cc_info FROM user
WHERE date = ?

The above query fails with Error: syntax error at: 2:1 expecting: end of query but got:something

Solution:

You will have to use group by:

SELECT cc_info FROM user
WHERE date = ?
GROUP BY cc_info

And if your table is large, consider using group by each

SELECT cc_info FROM user
WHERE date = ?
GROUP EACH BY cc_info

victor

posted on 30 Oct 19

Enjoy great content like this and a lot more !

Signup for a free account to write a post / comment / upvote posts. Its simple and takes less than 5 seconds

Copied