Solved

SQL Query - Reverse the order of results

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Read about achieving the basic levels of HRIS security in the workplace.
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
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…

736 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