access_time 2 months ago languageEnglish
more_vert

BigQuery SQL - Retrieve DISTINCT Values

visibility 8 comment 0

In earlier version of BigQuery SQL, DISTINCT clause is not supported. To retrieve distinct values, we had to use GROUP BY or Windowing function to deduplicate. In 2020, BigQuery already support DISTINCT clause thus we can directly use it in SELECT statement.

SELECT DISTINCT

WITH
  SRC AS (
  SELECT
    'A' AS Col1,
    1 AS Col2
  UNION ALL
  SELECT
    'A' AS Col1,
    1 AS Col2 )
SELECT
   DISTINCT *
FROM
  SRC;

Output (in JSON format):

[
  {
    "Col1": "A",
    "Col2": "1"
  }
]
copyright This page is subject to Site terms.
Like this article?
Share on

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts

Follow Kontext

Get our latest updates on LinkedIn or Twitter.

Want to contribute on Kontext to help others?

Learn more

More from Kontext

visibility 14
thumb_up 0
access_time 2 months ago
visibility 785
thumb_up 0
access_time 8 months ago
visibility 156
thumb_up 0
access_time 8 months ago