Created
February 21, 2019 10:40
-
-
Save marta-krzyk-dev/00226900697884056597004467462245 to your computer and use it in GitHub Desktop.
SQL: UNION vs UNION ALL
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 ALL allows duplicates, whereas UNION does not (returns only distinct rows) | |
SELECT CustomerName FROM orders | |
UNION | |
SELECT CustomerName FROM customers; | |
--Result: | |
--Mary | |
--John | |
--Bill | |
--Anton | |
SELECT CustomerName FROM orders | |
UNION ALL | |
SELECT CustomerName FROM customers; | |
--Result: | |
--Mary | |
--Mary | |
--Mary | |
--Mary | |
--John | |
--John | |
--Bill | |
--Bill | |
--Anton | |
--Anton | |
--Anton |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment