As the other answers say, It is being parsed as
SELECT { unordered_stuff UNION SELECT unordered_stuff } ORDER BY foo
Some, though I don't believe all, databases support an alternate disambigiouation syntax. This is from the Pg lists.
(SELECT * from foo where priority = 1 order by seniority)
UNION ALL
(select * from foo where priority > 1 order by seniority, priority)
Otherwise the ORDER BY is considered to apply to the whole UNION result
(it's effectively got lower binding priority than the UNION). Note also
that you *must* use UNION ALL, else UNION will attempt to eliminate
duplicates, and mess up the sort order while at it.
See also Bruno's solution nearby. Not sure which of these approaches
would be faster; try both.