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 |
|
tmaiden
Yak Posting Veteran
86 Posts |
Posted - 2006-10-10 : 11:08:04
|
I am trying to combine 2 queries, each with their own 'order by' and I am having trouble.This is just an example, not what I'm trying to do, my query is more elaberate but looks simular to this.SELECT TOP 10 *, 'FieldA' AS SortedByFROM TableAOrder By FieldA DescUNION ALLSELECT TOP 10 Precent *, 'FieldB' AS SortedByFROM TableAOrder By FieldB Asc Anyway not to get the following error?Server: Msg 156, Level 15, State 1, Line 34Incorrect syntax near the keyword 'UNION'. |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-10-10 : 11:13:19
|
| TrySelect * from(SELECT TOP 10 *, 'FieldA' AS SortedByFROM TableAOrder By FieldA Desc) T1UNION ALLSelect * from(SELECT TOP 10 Precent *, 'FieldB' AS SortedByFROM TableAOrder By FieldB Asc) T2MadhivananFailing to plan is Planning to fail |
 |
|
|
tmaiden
Yak Posting Veteran
86 Posts |
Posted - 2006-10-10 : 11:20:11
|
| Ahh, perfect! Thanks! |
 |
|
|
|
|
|