UNION versus UNION ALL, lessons in minutiae

(At the end we break this down for LINQ to SQL, so stay tuned in!)

In SQL server programming (and set theory) a Union combines all rows from two result sets. In SQL programming these two result sets must have the same number and type of columns. While these two operations perform very similar tasks, their performance can be quite different. So, to demonstrate a UNION we will use this query from the AdventureWorks database. This query has two sub-queries looking for different strings in the product number column. The strings are very similar and will likely have overlapping columns, but the UNION operation will filter these out. Lets, look at an example... More...