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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:37:44+00:00 2026-06-16T05:37:44+00:00

I would like to rank my entries based on a total score column but

  • 0

I would like to rank my entries based on a total score column but I need to have ties if the scores are the same. The query below successfully ranks, but the rank goes up even if there is a tie.

Here is my current query:

SET @r=0; UPDATE table SET rank= @r:= (@r+1) WHERE `complete` = 1 ORDER BY score DESC;

I have been reading a ton of posts but haven’t found an explanation of doing this in an UPDATE.

+----+-----------+-------------+-------------+
| id | lName     | score       | rank        |
+----+-----------+-------------+-------------+
|  1 | Rosebrock |          50 |           5 |
|  2 | Kolley    |          58 |           3 |
|  3 | Bartley   |          11 |           6 |
|  4 | Bell      |          58 |           4 |
|  5 | Daugherty |          63 |           2 |
| 85 | Harp      |          78 |           1 |
+----+-----------+-------------+-------------+
  • 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-16T05:37:45+00:00Added an answer on June 16, 2026 at 5:37 am
    create table scores (
      id INT NOT NULL AUTO_INCREMENT,
      score INT NOT NULL,
      rank INT NOT NULL DEFAULT 0,
      PRIMARY KEY (id)
    ) ENGINE=InnoDB;
    
    INSERT INTO scores (score) VALUES (1), (20), (10), (25), (10), (20);
    
    SET @rank=0, @score=-100;
    
    UPDATE scores 
    SET rank=IF(@score=(@score:=score), @rank, @rank:=@rank+1)
    ORDER BY score;
    

    Same here: http://sqlfiddle.com/#!2/90c3b/2/0

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

Sidebar

Related Questions

Suppose I have 2 tables, query and rank. I would like to know if
What i would like to do is have a Top 10, but the 10th
I have the following query that I would like to convert to LINQ to
I would like to have this $sort_flags array available within the compare_by_flags function, but
I have the following query where I would like to return two result sets.
I would like to rank sequential rows with the null value inside a group
I would like to know if there is any easy way to rank blog
I have a table that I would like to be able to present ranked
I am able to compare Strings fine, but would like to know how I
I need to build a sorter class for a List. I would like the

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.