[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

SQL Query - Reverse the order of results

Posted on 2006-11-07
2
Medium Priority
?
1,441 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 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

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

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

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
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…
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

656 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