Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
ConradK
Posting Yak Master
140 Posts |
Posted - 2010-05-14 : 12:18:22
|
| *sigh*, not sure why I can't find an answer to this.t11t22t33select * from t1unionselect * from t2union select * from t3I'm expecting something like123but am getting312.... why?!?!? Of course I've simplified the data a bit here. The data requires a header and footer, I'm using union to create thsoe headers and footers, but the footer is floating to the top.Put simply, how do I controll the order of the queries it unions? |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2010-05-14 : 12:20:52
|
Use it like ...select * from (select * from t1unionselect * from t2union select * from t3) torder by <desiredfield> |
 |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2010-05-14 : 12:39:10
|
quote: Originally posted by ConradK[br<snip>.... why?!?!? Of course I've simplified the data a bit here. The data requires a header and footer, I'm using union to create thsoe headers and footers, but the footer is floating to the top.Put simply, how do I controll the order of the queries it unions?
The WHY is that there is NO order without an ORDER BY clause. This the sample provided by Vijayisonly includes that and thus an ordered result set. :) |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-05-14 : 12:50:04
|
| there's no concept of first and last in SQL table without use of ORDER BY------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
ConradK
Posting Yak Master
140 Posts |
Posted - 2010-05-14 : 14:06:31
|
| X002548! Brilliant! |
 |
|
|
|
|
|
|
|