The ANSI/ISO specs are not at all ambiguous on this. An ORDER BY is not allowed for the SELECT statements within a UNION. It must come at the end and applied to the resulting UNION. Similarly, the column names in the result come from the first query in the UNION. Column names in the query on the right side of a UNION are immaterial. Unless we have reason to believe that PostgreSQL is non-compliant on this point, I don't think it is a good idea to slow the query down with the subquery. -Kevin >>> "Merlin Moncure" <merlin.moncure@xxxxxxxxxxxxx> >>> > Merlin Moncure wrote: > > hmm, try pushing the union into a subquery...this is better style > > because it's kind of ambiguous if the ordering will apply before/after > > the union. > > Seems to be a little slower. There's a new "subquery scan" step. I figured. However it's more correct, I'm not sure if the original query is necessarily guaranteed to give the right answer (in terms of ordering). It might though.