Solved

SQL Query - Reverse the order of results

Posted on 2006-11-07
2
1,387 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 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 125 total points
Comment Utility
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
Comment Utility
Nice one, thanks!
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

This article describes some very basic things about SQL Server filegroups.
CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now