Skip to content

Instantly share code, notes, and snippets.

@benjaminestes
Last active April 15, 2023 03:49
Show Gist options
  • Select an option

  • Save benjaminestes/5846a4da1f68621b607e98f23053de43 to your computer and use it in GitHub Desktop.

Select an option

Save benjaminestes/5846a4da1f68621b607e98f23053de43 to your computer and use it in GitHub Desktop.
Semidifference or semijoin operations in BigQuery
#standardSQL
WITH
a AS (
SELECT
num
FROM
UNNEST(GENERATE_ARRAY(1, 6)) AS num),
b AS (
SELECT
num
FROM
UNNEST(GENERATE_ARRAY(3, 8)) AS num)
SELECT
DISTINCT num
FROM
a WHERE
-- Or 'IN' for semijoin
(num) NOT IN (
SELECT
num
FROM
b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment