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 7994349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:06:29+00:00 2026-06-04T14:06:29+00:00

I use ROW_NUMBER() function to get 50 by 50 items from database table. @From

  • 0

I use ROW_NUMBER() function to get 50 by 50 items from database table.
@From parameter is row from which to start grabbing 50 rows. (First time it is 1 that 51,101,151 etc.)
I pass parameter @CityId to stored procedure and if first 60 rows in database are cityId=1 and cityId = 2 is in row 61 this stored procedure doesn’t return result.
But if I pass @From parameter 51 than it return me result.
What I did wrong here?

SELECT  RowConstrainedResult.*
FROM    ( SELECT    ROW_NUMBER() OVER 
( ORDER BY f.ItemCreatedOnDate DESC ) AS RowNum, 
f.*
FROM (
SELECT
      t.ItemIdId,
      t.ItemTypeId,
      t.CreatedOnDate as ItemCreatedOnDate,
      t.CityId as CityId
FROM   dbo.Items    as t
) f) AS RowConstrainedResult
WHERE   RowNum >= @From
    AND RowNum < @From + 50
    AND CityId = @CityId
  • 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-04T14:06:31+00:00Added an answer on June 4, 2026 at 2:06 pm

    In your version, ROW_NUMBER() is enumerating all rows. Move the predicate for cityid to the innermost select and ROW_NUMBER() will only enumerate the rows where cityid = 2.

    SELECT RowConstrainedResult.*
    FROM (
         SELECT ROW_NUMBER() OVER (ORDER BY f.ItemCreatedOnDate DESC) AS RowNum, 
                f.*
         FROM (
              SELECT t.ItemIdId,
                     t.ItemTypeId,
                     t.CreatedOnDate as ItemCreatedOnDate,
                     t.CityId as CityId
              FROM dbo.Items AS t
              WHERE CityId = @CityId
              ) AS f
         ) AS RowConstrainedResult
    WHERE RowNum >= @From AND 
          RowNum < @From + 50
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use the SUM function to count rows from 3 tables, which
I have table with few rows, after use hover mouse over row I want
I have an xml layout which I use for each row in my listview:
I'm trying to use jQuery to append a row to a table and to
How can I get the current selected row for UIPicker? I want to use
i never use sql server ROW_NUMBER() function. so i read some article regarding ROW_NUMBER(),PARTITION
I use Postgresql 9.1. I have a table and I would like to get
In SQL Server 2008, you can use the Row Constructor syntax to insert multiple
So basically I use jQuery for alternating row colours by selecting all the tr
When writing a row-level trigger in Oracle, I know that you can use the

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.