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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T16:07:07+00:00 2026-06-03T16:07:07+00:00

I am creating an SP which gives some result by applying distinct on it,

  • 0

I am creating an SP which gives some result by applying distinct on it, now I want to implement sever side paging, so I tried using Row_number on distinct result like:

    WITH CTE AS
    (
        SELECT ROW_NUMBER() OVER(ORDER BY tblA.TeamName DESC)
as Row,tblA.TeamId,tblA.TeamName,tblA.CompId,tblA.CompName,tblA.Title,tblA.Thumbnail,tblA.Rank,tblA.CountryId,tblA.CountryName
         FROM
         (
           --The table query starts with SELECT 
         )tblA
    )
        SELECT CTE.* FROM CTE
        WHERE CTE.Row BETWEEN @StartRowIndex AND @StartRowIndex+@NumRows-1
        ORDER BY CTE.CountryName

but rows are first assigned RowNumber then distinct get applied that is why I am getting duplicate values, how to get distinct rows first then get row numbers for the same.

Any solution on this? Am I missing something?
need answer ASAP.
thanks in advance!

  • 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-03T16:07:08+00:00Added an answer on June 3, 2026 at 4:07 pm

    Don’t you need to add “partition by” to your ROW_NUMBER statement?

    ROW_NUMBER() OVER(Partition by ___, ___, ORDER BY tblA.TeamName DESC) 
    

    In the blank spaces, place the column names you would like to create a new row number for. Duplicates will receive a number that is NOT 1 so you might not need the distinct.

    To gather the unique values you could write a subquery where the stored procedure only grabs the rows with a 1 in them.

    select * from
    (
      your code
    ) where row = 1
    

    Hope that helps.

    I’m not sure why you’re doing this:

    WHERE CTE.Row BETWEEN @StartRowIndex AND @StartRowIndex+@NumRows-1 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating an application which tracks the users location using GPS, stores the
I am creating a webpage which is using asp .net as its backend. I
I'm creating a database using entity framework code first and I'm having some issues
I frequently find myself creating classes which use this form (A): abstract class Animal
I creating a program which send newsletter with a background image. It works fine
We are creating a service which requires MSMQ, and it might happen the boxes
I am creating a utility which depends on libassuan aside other depends. While these
I am creating an object which tracks changes (Updates) regarding the creation, updating and
I'm creating an site which allows users to upload photos. It's a linux server.
I'm creating a cache which is going to contain records in Delphi 2007. Each

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.