BigQuery SQL - Retrieve DISTINCT Values

visibility 368 access_time 2 years ago languageEnglish timeline Stats
timeline Stats
Page index 0.83

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.

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts

More from Kontext
BigQuery SQL - WITH Clause
visibility 437
thumb_up 0
access_time 2 years ago
Teradata: PIVOT and UNPIVOT Clause
visibility 1,047
thumb_up 0
access_time 10 months ago
Pandas - Save DataFrame to BigQuery
visibility 2,028
thumb_up 0
access_time 2 years ago
Pandas - Save DataFrame to BigQuery