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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:41:41+00:00 2026-05-15T12:41:41+00:00

Is there any way I can get the actual row number from a query?

  • 0

Is there any way I can get the actual row number from a query?

I want to be able to order a table called league_girl by a field called score; and return the username and the actual row position of that username.

I’m wanting to rank the users so i can tell where a particular user is, ie. Joe is position 100 out of 200, i.e.

User Score Row
Joe  100    1
Bob  50     2
Bill 10     3

I’ve seen a few solutions on here but I’ve tried most of them and none of them actually return the row number.

I have tried this:

SELECT position, username, score
FROM (SELECT @row := @row + 1 AS position, username, score 
       FROM league_girl GROUP BY username ORDER BY score DESC) 

As derived

…but it doesn’t seem to return the row position.

Any ideas?

  • 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-15T12:41:42+00:00Added an answer on May 15, 2026 at 12:41 pm

    You may want to try the following:

    SELECT  l.position, 
            l.username, 
            l.score,
            @curRow := @curRow + 1 AS row_number
    FROM    league_girl l
    JOIN    (SELECT @curRow := 0) r;
    

    The JOIN (SELECT @curRow := 0) part allows the variable initialization without requiring a separate SET command.

    Test case:

    CREATE TABLE league_girl (position int, username varchar(10), score int);
    INSERT INTO league_girl VALUES (1, 'a', 10);
    INSERT INTO league_girl VALUES (2, 'b', 25);
    INSERT INTO league_girl VALUES (3, 'c', 75);
    INSERT INTO league_girl VALUES (4, 'd', 25);
    INSERT INTO league_girl VALUES (5, 'e', 55);
    INSERT INTO league_girl VALUES (6, 'f', 80);
    INSERT INTO league_girl VALUES (7, 'g', 15);
    

    Test query:

    SELECT  l.position, 
            l.username, 
            l.score,
            @curRow := @curRow + 1 AS row_number
    FROM    league_girl l
    JOIN    (SELECT @curRow := 0) r
    WHERE   l.score > 50;
    

    Result:

    +----------+----------+-------+------------+
    | position | username | score | row_number |
    +----------+----------+-------+------------+
    |        3 | c        |    75 |          1 |
    |        5 | e        |    55 |          2 |
    |        6 | f        |    80 |          3 |
    +----------+----------+-------+------------+
    3 rows in set (0.00 sec)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way I can get my Python code syntax highlighted in Microsoft
Is there any way I can get VS2008 to provide further detail on how
Is there any way I can get jQuery to perform a function when you
Is there any way I can get a share picker like the one seen
I wanted to ask if there is any way i can get path of
I can't believe I'm asking this but, is there any way to get Chrome
Is there any way we can fetch X509 Public Cetrificates using c# from AD
Is there any way to get at the actual messages generated during the evaluation
Is there any way to get the actual data that will be sent when
Is there any way to get information from my model during a result flagged

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.