[thelist] SQL Union and order by problem

r937 rudy at r937.com
Thu Oct 18 13:24:06 CDT 2007


> i want to make query from union of 2 subqueries.
> subquery 1 : simple query with order by b desc
> subquery 2 : simple query with order by b asc

sorry, you cannot put ORDER BY into the subqueries to achieve this result

a UNION query should have only one ORDER BY, at the end, to sort the entire 
combined results from all SELECTs in the UNION

that said, you could have a column with the value -b in the first SELECT, 
which can then combine with the column b values from the second SELECT, so 
that the overall ORDER BY would be ASC

rudy
http://r937.com/ 





More information about the thelist mailing list