Union allows for combining a number of Select statements together, one after the other.

 

The difference between Union and Union All, is that Union will remove duplicate rows, and Union All will include duplicate rows.

 

To do an Order By for the data I have Unioned together, I can wrap the Unions into a bracketed  From, and do the Order By after this Temp Tabled From…

 

Select

*

From

(

Select

FirstName

,MiddleName

,LastName

From

[Person].[Person]

Union — This has no duplicates.

— Union All — This does have duplicates.

Select

FirstName

,MiddleName

,LastName

From

[Person].[Person_Names]

) As Tmp

Order By

Tmp.FirstName, Tmp.LastName

 

Advertisements