Recently i received a question in SQL Server, "Which is faster Union or Union All?"
Answer : Union All is Faster then Union.
UNION -> you get DISTINCT records from both the tables.
UNION ALL-> Get all records from both the tables with duplicates.
If you check execution plan, UNION has extra "sort" operator, which makes it costlier compared to "UNION ALL". However, it's necessary sometimes to use "UNION", if the data sources has duplicate records and we wants to avoid duplicates.
SQL Server Interview Questions · · · ·