The syntax of
UNION
is given here.
http://msdn.microsoft.com/en-us/library/ms180026.aspx[
^]
As seen from here the
WHERE
is not part of
UNION
statement.
Essentially
UNION
combines the results from two query expressions and
UNION ALL
combines all rows from both the query expressions including duplicate rows as explained here
http://www.fmsinc.com/free/NewTips/SQL/SQLtip5.asp[
^]
So
UNION
can be used with query expressions containing
WHERE
clause, but the
WHERE
is not part of the
UNION
statement.
As
Espen Harlinn said in his solution the ORDER BY clause sorts the full result set.
The order of
ORDER BY
is important as shown in the first link at
C. Using UNION of two SELECT statements with ORDER BY, with sample of both incorrect and correct placement of
ORDER BY
clause