SQL to get range of results in alphabetical order
- by Tom Gullen
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!