Difference Between Union And Union All?

Forums SQLDifference Between Union And Union All?
Staff asked 3 years ago

Answers (1)

Add Answer
Staff answered 3 years 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