Interviews3 answers
What is the difference between Union and Union All?
3 Answers
UNION: only keeps unique records. UNION ALL: keeps all records, including duplicates
Nisha RegilPosted Sep 11, 2020, 4:49 AM EDT
Union- It combines two more queries and removes the duplicates.
UnionAll- It combines two more queries and keeps the duplicates.
For example: TableA has 1,2,3 and Table B has 3,4,5
Union Result will be 1,2,3,4,5 (It removes the duplicate 3)
Union All Result will be 1,2,3,3,4,5 (It keeps the duplicate 3)
Which one will be faster?
Union All will be faster, as it does not remove the duplicates.
Navaneeth KrishnanPosted Aug 12, 2020, 6:38 PM EDT


