Skip to content

Instantly share code, notes, and snippets.

@dmreiland
Forked from yancya/EXCEPT.sql
Created June 13, 2019 14:51
Show Gist options
  • Save dmreiland/bdcb545b44f34f868ddbdc89a3db506c to your computer and use it in GitHub Desktop.
Save dmreiland/bdcb545b44f34f868ddbdc89a3db506c to your computer and use it in GitHub Desktop.
INTERSECT and EXCEPT for BigQuery
#standardsql
WITH a AS (
SELECT * FROM UNNEST([1,2,3,4]) AS n
), b AS (
SELECT * FROM UNNEST([4,5,6,7]) AS n)
SELECT * FROM a
EXCEPT DISTINCT
SELECT * FROM b
-- | n |
-- | 1 |
-- | 2 |
-- | 3 |
#standardsql
WITH a AS (
SELECT * FROM UNNEST([1,2,3,4]) AS n
), b AS (
SELECT * FROM UNNEST([4,5,6,7]) AS n)
SELECT * FROM a
INTERSECT DISTINCT
SELECT * FROM b
-- | n |
-- | 4 |
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment