SQL to get range of results in alphabetical order

Posted by Tom Gullen on Stack Overflow See other posts from Stack Overflow or by Tom Gullen
Published on 2011-06-25T00:02:14Z Indexed on 2011/06/25 8:22 UTC
Read the original article Hit count: 229

Filed under:
|
|
|

I have a table, tblTags which works in much the same way as StackOverflows tagging system.

When I view a tags page, let's say the tag Tutorial I want to display the 10 tags before and after it in alphabetical order.

So if we are given the tag Tutorial of ID 30 how can we return a record set in the order resembling:

Tap
Tart
> Tutorial
Umbrellas
Unicorns
Xylaphones

I have thought of ways of doing this, badly, in my opinion as they involve retrieving ugly amounts of data.

I'm not sure if it's possible to do something along the lines of (pseudo):

SELECT RANGE(0 - 30) FROM tblTags ORDER BY Name ASC

But how do you know the position of the tutorial tag in the list in an efficient manner without traversing the entire list until you find it?

I'm using SQL Server 2008 R2 Express with LINQ if it makes any difference, SQL queries or LINQ would be great answers, thanks!

© Stack Overflow or respective owner

Related posts about sql

Related posts about LINQ