0

I need to use a database using ASP.NET and to take the top 10 items and sort them in ascending order within the top 10. I have used combinations of the following and have not got them to work:

TOP 10 [rows] LIMIT (not supported) ORDER BY [rows] ASC

user963070
  • 629
  • 2
  • 19
  • 24
  • For clarification, I want to take the top 10 items and order only the top 10 items (and still not show the other items after the tenth) so I want to take the top 10 first and then sort second. – user963070 Mar 27 '13 at 04:42
  • Have you tried `SELECT TOP(10) FROM ORDER BY ASC`? You have to pick a column to order the rows by. – Tim Mar 27 '13 at 04:44
  • what do you want the top 10 to be based on, tables are in some order, even if you neglect to specify one. – BlackICE Mar 27 '13 at 04:45

1 Answers1

0

You could do something like this (may not be 100% here, don't have SQL in front of me), but I wouldn't recommend not specifying some kind of order by on the inner select, as if the underlying clustered index changes that would change your results.

select *
from 
(select top 10 *
from mytable) as x
order by x.mycolumn asc
BlackICE
  • 8,816
  • 3
  • 53
  • 91
  • Curious - why the subquery? Is that to ensure the ordering is done on only the 10 rows selected, and not all the rows in the table? – Tim Mar 27 '13 at 04:53
  • because he didn't want the 10 items ordered initially, at least that what I got from the badly worded question. – BlackICE Mar 27 '13 at 04:54
  • got it. Makes sense (to me at least). Thanks. – Tim Mar 27 '13 at 04:56
  • Nevermind. I was using the wrong database. The correct one had only 10 elements. I am so sorry. Please close this thread. I am an idiot. – user963070 Mar 27 '13 at 20:58