UNION VS UNION ALL:
Both UNION and UNION ALL concatenate the result of two different SQLs. They differ in the way they handle duplicates.
- UNION performs a DISTINCT on the result set, eliminating any duplicate rows.
- UNION ALL does not remove duplicates, and it therefore faster than UNION.
Example: If we have two tables, 1) Employee and 2) Customer
- Employee table data:

- Customer table data:

- UNION Example (It removes all duplicate records):

- UNION ALL Example (It just concatenate records, not eliminate duplicates, so it is faster than UNION):

Comments
Post a Comment