Solved

SQL Query - Reverse the order of results

Posted on 2006-11-07
2
1,433 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 125 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
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…
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…

690 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