-
-
Save dmreiland/bdcb545b44f34f868ddbdc89a3db506c to your computer and use it in GitHub Desktop.
INTERSECT and EXCEPT for BigQuery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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