Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

SQL Query - Reverse the order of results

Posted on 2006-11-07
2
Medium Priority
?
1,443 Views
Last Modified: 2012-06-21
I have the following query that returns the last 12 months of data:

SELECT TOP 12 pk_AssetsID, TheYear, TheMonth, TheValue, Colour, fk_fundID
FROM         AssetsUnderManagement
 WHERE fk_FundID = 1
ORDER BY TheYear DESC, TheMonth DESC

And returns the following recordset:

pk_AssetsID TheYear TheMonth TheValue    Colour     fk_fundID  
----------- ------- -------- ----------- ---------- -----------
25          2006    10       1142        &H00A0BA   1
24          2006    9        1166        &H00A0BA   1
23          2006    8        1137        &H00A0BA   1
11          2006    7        1066        &H00A0BA   1
12          2006    6        970         &H00A0BA   1
13          2006    5        836         &H00A0BA   1
5           2006    4        672         &H00A0BA   1
14          2005    12       367         &H00A0BA   1
15          2005    11       315         &H00A0BA   1
16          2005    10       257         &H00A0BA   1
17          2005    9        193         &H00A0BA   1
18          2005    8        130         &H00A0BA   1

But I need the results to be returned in the reverse order.  I can't change the ORDER BY clause as since it's returning the last 12 months it'd return the oldest 12 months.

Any ideas?
0
Comment
Question by:equentin
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 17889245
What about this:
SELECT *
FROM  (
SELECT TOP 12 pk_AssetsID, TheYear, TheMonth, TheValue, Colour, fk_fundID
FROM         AssetsUnderManagement
 WHERE fk_FundID = 1
ORDER BY TheYear DESC, TheMonth DESC
)
ORDER BY TheYear ASC, TheMonth ASC
0
 

Author Comment

by:equentin
ID: 17889314
Nice one, thanks!
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, we’ll look at how to deploy ProxySQL.
Creating a Cordova application which allow user to save to/load from his Dropbox account the application database.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question