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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:24:14+00:00 2026-06-11T00:24:14+00:00

Let’s say I have a table with the following columns: p_id userid points Let’s

  • 0

Let’s say I have a table with the following columns:


p_id

userid

points


Let’s say these columns have over 5000 records. So we actually have users with points. Each user has an unique row for their point record. Imagine that every user can get points on the website by clicking somewhere. When they click I update the database with the points they get.

So we have a table with over 5000 records of people who have points, right? Now I would like to order them by their points (descending), so the user with the most point will be at the top of the page if I run a MySQL query.

I could do that by simply running a query like this:

SELECT `p_id` FROM `point_table` ORDER BY `points` DESC

This query would give me all the records in a descending order by points.

Okay, here my problem comes, now (when it is ordered) I would like to display each user which place are they actually. So I’d like to give each user something like this: “You are 623 of 5374 users”. The problem is that I cannot specify that “623” number.

I would like to run a query which is order the table by points it should “search” or count the row number, where their records are and than return that value to me.

Can anyone help me how to build a query for this? It would be a really big help. Thank you.

  • 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-11T00:24:15+00:00Added an answer on June 11, 2026 at 12:24 am

    This answer should work for you:

    SET @rank=0;
    SELECT @rank:=@rank+1 AS rank, p_id FROM point_table ORDER BY points DESC;
    

    Update: You might also want to consider to calculate the rank when updating the points and saving it to an additional column in the same table. That way you can also select a single user and know his rank. It depends on your use cases what makes more sense and performs better.

    Update: The final solution we worked out in the comments looked like this:

    SELECT
    rank, p_id
    FROM
        (SELECT
         @rank:=@rank+1 AS rank, p_id, userid
         FROM
         point_table, (SELECT @rank := 0) r
         ORDER BY points DESC
        ) t
    WHERE userid = intval($sessionuserid); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have the following text: (example) <table> <tr> <td> <span>col1</span> </td> <td>col2</td>
Let's say I have a table with a Color column. Color can have various
Let's say I have the following object: var VariableName = { firstProperty: 1, secondProperty:
Let's say I have the following classes : public class MyProductCode { private String
Let's say I have table with column 'URL' whrere I store urls like this
Let's say I have the following HTML snippet: <div abc:section=section1> <p>Content...</p> </div> <div abc:section=section2>
Let's say I have a Products table, ProductsCategory table and a Category table. The
Let say I have the following desire, to simplify the IConvertible's to allow me
Let's say you have a class called Customer, which contains the following fields: UserName
Let's say I have the following two lists of tuples myList = [(1, 7),

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.