Created
December 15, 2017 11:04
-
-
Save yancya/bf38d1b60edf972140492e3efd0955d0 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