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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:04:21+00:00 2026-06-17T09:04:21+00:00

I have a table in mySql which has the users ID and scores. What

  • 0

I have a table in mySql which has the users ID and scores.

What I would like to do is organise the table by scores (simple) but then find where a certain user ID sits in the table.

So far I would have:

SELECT * FROM table_score
ORDER BY Score DESC

How would I find where userID = '1234' is (i.e entry 10 of 12)

  • 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-17T09:04:21+00:00Added an answer on June 17, 2026 at 9:04 am

    The following query will give you a new column UserRank, which specify the user rank:

    SELECT 
      UserID, 
      Score, 
      (@rownum := @rownum + 1) UserRank 
    FROM table_score, (SELECT @rownum := 0) t 
    ORDER BY Score DESC;
    

    SQL Fiddle Demo

    This will give you something like:

    | USERID | SCORE | USERRANK |
    -----------------------------
    |      4 |   100 |        1 |
    |     10 |    70 |        2 |
    |      2 |    55 |        3 |
    |   1234 |    50 |        4 |
    |      1 |    36 |        5 |
    |     20 |    33 |        6 |
    |      8 |    25 |        7 |
    

    Then you can put this query inside a subquery and filter with a userId to get that user rank. Something like:

    SELECT
      t.UserRank
    FROM
    (
       SELECT *, (@rownum := @rownum + 1) UserRank 
       FROM table_score, (SELECT @rownum := 0) t 
       ORDER BY Score DESC
    ) t
    WHERE userID = '1234';
    

    SQL Fiddle Demo

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

Sidebar

Related Questions

I have a MySQL table which has a product_id field (big integer) 1102330008 1102330025
I have a huge MySQL table which has its rows encoded in UTF-8 twice.
I have a table in MySQL 4.0 which currently has a year field as
if i have a table which has columns with fixed lenght, Will mySQL count
I have a table which is being dynamically populated from MySQL. The table has
I have a MYSQL-Table which stores scores. Every time a user improves a new
I have two tables, the first is a 'users' table which has a column
Possible Duplicate: Datetime vs Timestamp? I have a Mysql table, which has a column
I Have MySQL DB table tbl_users , which has two uid , name ,
Our MySQL database has a users table with a logged_in, BOOL column which is

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.