BigQuery SQL - UNION ALL

visibility 350 access_time 2 years ago languageEnglish

BigQuery supports UNION ALL clause in standard SQL though it doesn't support UNION clause.

BigQuery UNION ALL

The following statement shows an example of UNION ALL clause in SELECT statement.

SELECT
  'A' AS Col1,
  1 AS Col2
UNION ALL
SELECT
  'A' AS Col1,
  1 AS Col2

Output (in JSON format):

[
  {
    "Col1": "A",
    "Col2": "1"
  },
  {
    "Col1": "A",
    "Col2": "1"
  }
]

UNION DISTINCT

UNION DISTINCT is similar as UNION (without ALL) in other databases:

SELECT
    'A' AS Col1,
    1 AS Col2
  UNION DISTINCT
  SELECT
    'A' AS Col1,
    1 AS Col2

Output (in JSON format):

[
  {
    "Col1": "A",
    "Col2": "1"
  }
]
info Last modified by Raymond 2 years ago 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

timeline Stats
Page index 0.81
More from Kontext
Differences between BigQuery and Cloud BigTable
visibility 208
thumb_up 0
access_time 2 years ago
Differences between BigQuery and Cloud BigTable
BigQuery - First/Last Day of Month
visibility 5,800
thumb_up 0
access_time 2 years ago
Teradata: FIRST_VALUE and LAST_VALUE Funtions
visibility 425
thumb_up 0
access_time 10 months ago