Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Return last 10 records 1

Status
Not open for further replies.
Joined
Aug 22, 2002
Messages
113
Location
FR
Hello,

I would like to restrict the output of my query to the last 10 records.
I have used the TOP option with SORT BY DESC but it outputs the last records first.
I know that a way to get the last records last is by using a sub-query or a view but i've been having some trouble with those.
Here's my query :

Code:
 SELECT TOP 10 SUM(Sys_used) + SUM(isnull(App_used,0.0)) + SUM(isnull(Data_used,0.0)) + SUM(isnull(Log_used,0.0)), Week FROM diskusage WHERE Category = '$categ' GROUP BY Week ORDER BY Week DESC

I haven't been able to create a sub-query to get the results I need.

Would you help me building my sub-query?

Thanks for your help.


 
Code:
 SELECT total,week 
  from (select TOP 10 SUM(Sys_used) +   SUM(isnull(App_used,0.0)) + 
SUM(isnull(Data_used,0.0)) + 
SUM(isnull(Log_used,0.0)) as total, 
Week 
FROM diskusage 
WHERE Category = '$categ' 
GROUP BY Week 
ORDER BY Week DESC) dt
order by week asc
 
It worked perfectly!

Thank you very much!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top