SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Old Forums
 CLOSED - General SQL Server
 selecting bottom 5 results of an sql query
 Forum Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

delboy2006
Starting Member

4 Posts

Posted - 01/08/2006 :  10:06:45  Show Profile
Hi,

Im having trouble selecting the bottom 5 results fo an sql query.
if for example I have a result set of numbers from 1 - 10, the below sql query will return the bottom 5 results but back to front.

SELECT TOP 5
id, name
FROM
t_projects

ORDER BY

DESC

basically the above returns 10,9,8,7,6, but I want it to return 6,7,8,9,10

can anybody help?

Thanks in advance

sachinsamuel
Constraint Violating Yak Guru

India
383 Posts

Posted - 01/08/2006 :  10:22:31  Show Profile
Try

select * from
(
SELECT TOP 5
id, name
FROM
t_projects
ORDER BY
id
DESC
)
A
order by A.Id

Regards
Sachin



Don't sit back because of failure. It will come back to check if you still available. -- Binu
Go to Top of Page

Srinika
Flowing Fount of Yak Knowledge

Sri Lanka
1378 Posts

Posted - 01/08/2006 :  10:23:37  Show Profile
Select * from 
(SELECT TOP 5 id, name FROM t_projects ORDER BY id DESC) as Q1
order by id
Go to Top of Page

delboy2006
Starting Member

4 Posts

Posted - 01/08/2006 :  10:31:57  Show Profile
thanks, that works a treat. Much appreciated!
Go to Top of Page
  Previous Topic Topic Next Topic  
 Forum Locked
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000