Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Old Forums
 CLOSED - General SQL Server
 selecting bottom 5 results of an sql query

Author  Topic 

delboy2006
Starting Member

4 Posts

Posted - 2006-01-08 : 10:06:45
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

383 Posts

Posted - 2006-01-08 : 10:22:31
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
Master Smack Fu Yak Hacker

1378 Posts

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

delboy2006
Starting Member

4 Posts

Posted - 2006-01-08 : 10:31:57
thanks, that works a treat. Much appreciated!
Go to Top of Page
   

- Advertisement -