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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:37:45+00:00 2026-05-28T03:37:45+00:00

I have a table of items that users are allowed to vote on. In

  • 0

I have a table of items that users are allowed to vote on. In this table, there is a votes column, that holds the number of votes that item has accumulated, and a rank column, that is a ranking of all items based on the number of votes they have (i.e. most votes gets rank 1, second most gets rank 2, etc.)

Currently, I’m recalculating the rank of every item after every vote. That is, when a user votes, I add one to that item’s votes column, and then update every rank with the following query:

SET @rank = 0
UPDATE items SET rank = @rank := @rank + 1 ORDER BY votes DESC

This works for the most part, but doesn’t take in to account voting ties. If I have votes [10, 4, 3, 0], I would expect ranks [1, 2, 3, 4]. However, if I have votes [10, 10, 3, 0], I would like ranks [1, 1, 3, 4]. This doesn’t happen; I still get ranks [1, 2, 3, 4].

How can I incorporate ties like I’ve described above?

  • 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-28T03:37:46+00:00Added an answer on May 28, 2026 at 3:37 am

    This inelegant solution would return what you desire:

    update ITEMS I1
       set rank =
             (select count(*)
                from ITEMS I2
               where I2.VOTES >= I1.VOTES)
             - (select count(*) - 1
                  from ITEMS I3
                 where I3.VOTES = I1.VOTES)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table called Users that has a column called deleted, a boolean
I have a table of items that users have bought, within that table there
I have a following table using MVC that shows number of items the user
I have a bill of materials table that is set up like this: item
I have an app that users choose items and then it fills a table
I have one table, assume that there are 2 users, user A and user
So lets say I have a join table that joins users and items. The
I have a table full of items that each have a unique ItemID .
let's say that I have a table called Items (ID int, Done int, Total
I have a recordset loop that creates a table, and every 9 items it

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.