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

  • Home
  • SEARCH
  • 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 8783145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:45:19+00:00 2026-06-13T20:45:19+00:00

I have been trying to understand a little bit about how to implement custom

  • 0

I have been trying to understand a little bit about how to implement custom paging in SQL, for instance reading articles like this one.

I have the following query, which works perfectly. But I would like to implement paging with this one.

SELECT TOP x PostId FROM ( SELECT PostId, MAX (Datemade) as LastDate
 from dbForumEntry 
 group by PostId ) SubQueryAlias
 order by LastDate desc

What is it I want

I have forum posts, with related entries. I want to get the posts with the latest added entries, so I can select the recently debated posts.

Now, I want to be able to get the “top 10 to 20 recently active posts”, instead of “top 10”.

What have I tried

I have tried to implement the ROW functions as the one in the article, but really with no luck.

Any ideas how to implement it?

  • 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-06-13T20:45:20+00:00Added an answer on June 13, 2026 at 8:45 pm

    In SQL Server 2012 it is very very easy

    SELECT col1, col2, ...
     FROM ...
     WHERE ... 
     ORDER BY -- this is a MUST there must be ORDER BY statement
    -- the paging comes here
    OFFSET     10 ROWS       -- skip 10 rows
    FETCH NEXT 10 ROWS ONLY; -- take 10 rows
    

    If we want to skip ORDER BY we can use

    SELECT col1, col2, ...
      ...
     ORDER BY CURRENT_TIMESTAMP
    OFFSET     10 ROWS       -- skip 10 rows
    FETCH NEXT 10 ROWS ONLY; -- take 10 rows
    

    (I’d rather mark that as a hack – but it’s used, e.g. by NHibernate. To use a wisely picked up column as ORDER BY is preferred way)

    to answer the question:

    --SQL SERVER 2012
    SELECT PostId FROM 
            ( SELECT PostId, MAX (Datemade) as LastDate
                from dbForumEntry 
                group by PostId 
            ) SubQueryAlias
     order by LastDate desc
    OFFSET 10 ROWS -- skip 10 rows
    FETCH NEXT 10 ROWS ONLY; -- take 10 rows
    

    New key words offset and fetch next (just following SQL standards) were introduced.

    But I guess, that you are not using SQL Server 2012, right? In previous version it is a bit (little bit) difficult. Here is comparison and examples for all SQL server versions: here

    So, this could work in SQL Server 2008:

    -- SQL SERVER 2008
    DECLARE @Start INT
    DECLARE @End INT
    SELECT @Start = 10,@End = 20;
    
    
    ;WITH PostCTE AS 
     ( SELECT PostId, MAX (Datemade) as LastDate
       ,ROW_NUMBER() OVER (ORDER BY PostId) AS RowNumber
       from dbForumEntry 
       group by PostId 
     )
    SELECT PostId, LastDate
    FROM PostCTE
    WHERE RowNumber > @Start AND RowNumber <= @End
    ORDER BY PostId
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been reading about bit operators in Objective-C in Kochan's book, Programming in
It maybe a little naive question but I have been trying to understand how
I have been trying to understand the way ActionScript's events are implemented, but I'm
okay i have been trying to understand this for hours i am learning VB
So, I have been trying to understand Socket.io lately, but I am not a
I have been trying to understand how to enhance the button quality of my
I have been using the jQuery nyroModal plugin for a little bit of time,
I have been trying to understand the Placement new concept. I searched on the
I have been going through tutorials, and have been trying to understand some things,
Have been trying to encrypt an xml file to a string so that I

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.