Difference Between Union And Union All?

Forums SQLDifference Between Union And Union All?
Staff asked 1 month ago

Answers (1)

Add Answer
Staff answered 1 month ago

UNION: It merges the results of many tables into a single result set and returns distinct records.
UNION ALL: It merges the results from many tables into a single result set and returns all of the records.

Example : 

SELECT name FROM Students   /* Fetch the union of queries */
UNION
SELECT name FROM Contacts;

SELECT name FROM Students   /* Fetch the union of queries with duplicates*/
UNION ALL
SELECT name FROM Contacts;

 

 

 

Subscribe

Select Categories