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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:26:33+00:00 2026-06-02T19:26:33+00:00

I read many topics about this problem but I can’t find the solution. I

  • 0

I read many topics about this problem but I can’t find the solution.

I have a table (called users) with the users of my website. They have points. For example:

+-----------+------------+
| User_id   | Points     |
+-----------+------------+
| 1         | 12258      |
| 2         | 112        |
| 3         | 9678       |
| 4         | 689206     |
| 5         | 1868       |
+-----------+------------+

On the top of the page the variable $user_id is set. For example the user_id is 4. Now I would like to get the rank of the user by points (output should be 1 if the user_id is 4).

Thank you very much!

  • 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-02T19:26:34+00:00Added an answer on June 2, 2026 at 7:26 pm
    SELECT 
        COUNT(*) AS rank 
    FROM users 
    WHERE Points>=(SELECT Points FROM users WHERE User_id=4)
    

    Updated with some more useful stuff:

    SELECT 
        user_id, 
        points, 
        (SELECT COUNT(*)+1 FROM users WHERE Points>x.points) AS rank_upper, 
        (SELECT COUNT(*) FROM users WHERE Points>=x.points) AS rank_lower 
    FROM 
        `users` x 
    WHERE x.user_id = 4
    

    which includes the range of ranks user is at. So for example if the scores for first five places are 5 4 3 3 3, the result would be:

    id points rank_upper rank_lower
    id 5      1          1
    id 4      2          2
    id 3      3          5
    id 3      3          5
    id 3      3          5
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have read many topics about UITableViews not refreshing on iPhone, but couldn't find
I have seen many questions about the above topics but none that address this.
I've read many topic on stackoverflow,and google, about this argument but i can't orient
I have read many topics about cut/copy to clipboard, but haven't found the answer
I read many topics here about it, but can't understand why my code does
I've read many posts on this topic, but none fits my problem. On an
I have read many questions about Android, J2ME and RecordStore , but I still
I have read many questions about the facebook login but until not I didnt
I've read many topics and every one tells me that this can't be done.
I read many answers on this topic and this is what i have understood

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.