Skip to content

Instantly share code, notes, and snippets.

@marta-krzyk-dev
Created February 21, 2019 10:40
Show Gist options
  • Save marta-krzyk-dev/00226900697884056597004467462245 to your computer and use it in GitHub Desktop.
Save marta-krzyk-dev/00226900697884056597004467462245 to your computer and use it in GitHub Desktop.
SQL: UNION vs UNION ALL
--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