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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:57:52+00:00 2026-06-13T15:57:52+00:00

The query below fetches a subset of rows from a table starting at row

  • 0

The query below fetches a subset of rows from a table starting at row 10 and ending at row 20. In addition, to save a query I need to return the total number of rows in the table. This is the best solution that I could think of. Are there any more efficient/elegant ways? In particular, I do not like the partition by 1 part.

select *
from (select count(*) over (partition by 1) as [count],
             row_number() over (order by [Name],[Description]) as [row],
             *
      from [Products]) as t
where row between 10 and 20
  • 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-13T15:57:54+00:00Added an answer on June 13, 2026 at 3:57 pm

    If you don’t like it, remove it!

    select *
    from (select count(*) over () as [count],
                 row_number() over (order by [Name],[Description]) as [row],
                 *
          from [Products]) as t
    where row between 10 and 20
    

    However, that aside, the query isn’t optimal. You should do the count the traditional way.

    select *
    from (select count(*) as [count]
            from [Products]) X
    cross join (
        select row_number() over (order by [Name],[Description]) as [row],
               *
          from [Products]) as t
    where row between 10 and 20
    

    You can put both of these together and press Ctrl-M, then execute. The plans will look quite different.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why the two query below return duplicate member_id and not the third? I need
I have a linq query which fetches all records from the customer table to
The query below returns rows that have both loginid and ip2 in the bumps
Why does the MySQL query below give error 1066 (Not unique table/alias: 'customer') ?
Need your help guys in forming a query. Example. Company - Car Rental Table
I have the query below that fetches 500 records according to certain criteria. The
testQuery() is the method I use to get all rows from table CATEGORIES public
The query below: SELECT i_adgroup_id, i_category_id FROM adgroupcategories_br WHERE i_adgroup_id IN ( SELECT i_adgroup_id
I'd like to fetch top n rows from my Azure Table with a simple
I am outputing 4 columns from a mysql query, but using the code below

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.