Created
October 2, 2020 16:59
-
-
Save mkwatson/b0c0a75a9d19e9abc413e128a7b46d53 to your computer and use it in GitHub Desktop.
This file contains 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
############################ | |
# UNION | |
############################ | |
WITH t1(v) AS | |
(VALUES (1), (1), (2)), | |
t2(v) AS | |
(VALUES (2), (2), (3)) | |
(SELECT DISTINCT v FROM t1) | |
UNION | |
(SELECT DISTINCT v FROM t2) | |
# reults | |
# v | |
# 1 2 | |
# 2 1 | |
# 3 3 | |
############################ | |
# UNION ALL | |
############################ | |
WITH t1(v) AS | |
(VALUES (1), (1), (2)), | |
t2(v) AS | |
(VALUES (2), (2), (3)) | |
(SELECT DISTINCT v FROM t1) | |
UNION ALL | |
(SELECT DISTINCT v FROM t2) | |
# reults | |
# v | |
# 1 3 | |
# 2 1 | |
# 3 2 | |
# 3 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment