Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6058275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:34:54+00:00 2026-05-23T08:34:54+00:00

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

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T08:34:55+00:00Added an answer on May 23, 2026 at 8:34 am

    Building off Jacob’s UNION suggestion, you use a table variable to select the matching TagID’s into and then join back against the Tag table to get the matching records. It’s not as elegant as I would like, but it does work.

    As a side note, I think the UNION approach would work, but AFAIK SQL Server only allows ORDER BY on the last SELECT, and that ORDER BY applies to the entire result set (this post also states the same thing).

    DECLARE @tags AS TABLE(TagID INT, Name VARCHAR(30))
    INSERT INTO @tags VALUES(1, 'a')
    INSERT INTO @tags VALUES(2, 'b')
    INSERT INTO @tags VALUES(3, 'c')
    INSERT INTO @tags VALUES(4, 'd')
    INSERT INTO @tags VALUES(5, 'e')
    INSERT INTO @tags VALUES(6, 'f')
    INSERT INTO @tags VALUES(7, 'g')
    INSERT INTO @tags VALUES(8, 'h')
    INSERT INTO @tags VALUES(9, 'i')
    INSERT INTO @tags VALUES(10, 'j')
    
    DECLARE @selectedTags AS TABLE(TagID INT)
    INSERT INTO @selectedTags
    SELECT TOP 2 TagID FROM @tags WHERE Name < 'e' ORDER BY Name DESC
    INSERT INTO @selectedTags
    SELECT TOP 2 TagID FROM @tags WHERE Name >= 'e' ORDER BY Name
    
    SELECT * 
    FROM @tags T
    JOIN @selectedTags ST ON ST.TagID = T.TagID
    ORDER BY T.Name
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have table with ajax paging, i can select any page and view data,
I have table view which is showing list of files to download. When I
I have table view which is populated from an array grabbed from a url.
I have table [HTML Table] on page I want to delete record from table
I have table cell which has class cellActive. Which has following defination .cellActive{background:#DDDDDD} Now
I have table one which looks like this. And I want to get data
I have table which is connected to datagridview and I would like to enter
I have table which will only contain information about files, so, as the file
I have table with pageId, parentPageId, title columns. Is there a way to return
I have table A and table B, same schemas. I want to insert certain

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.