8 ms·
No need to wrap the union queries in a new select to order the result. An order by after the last select in the unions orders the whole result set as long as th
by croes 6y ago
No need to wrap the union queries in a new select to order the result.
An order by after the last select in the unions orders the whole result set as long as the column names match in each part of the union.
- rrrrrrrrrrrryan 6y agoThis depends on the database engine. The syntax will error out in some (perhaps most).
- croes 6y agoWorks in mysql, postgres, oracle, MS, DB2. Can you name an engine where it fails?
- rrrrrrrrrrrryan 6y agoSeems I was completely wrong. I've learned something new today - thanks.
- AdrianB1 6y agoThat works in MS SQL, not guaranteed in others.
- croes 6y agoWorks in mysql, postgres, oracle, MS, DB2