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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:31:04+00:00 2026-06-07T11:31:04+00:00

I want to create hiscore list, but I have trouble doing it. This is

  • 0

I want to create hiscore list, but I have trouble doing it. This is my hiscore table and for every game I write user score into this table.

This is how my hiscore table look like:

id    user_id    user_name    score    entry_date
-----------------------------------------------------------
1      1         tom          500      2012-06-05 14:30:00
2      1         tom          500      2012-06-05 10:25:00
3      2         jim          300      2012-06-05 09:20:00
4      2         jim          500      2012-06-05 09:22:00
5      3         tony         650      2012-06-05 15:45:00

I want to get first 3 MAX scores, but I have to make sure if they have same score then I should take score that is first entered (based on entry_date column)

The query returned should be something like this.

1.  3      tony     650      2012-06-05 15:45:00     <- hi have to be first, because he have top score
2.  2      jim      500      2012-06-05 09:22:00     <- jim have the same score as tom, but he make that score before tom did so he is in second place
3.  1      tom      500      2012-06-05 10:25:00     <- tom have 2 entries with the same score, but we only take the one with smallest date

This is SQL query that I wrote but with that query i am getting hiscore list but it’s not ordered by entry_date and I don’t have any idea how to solve this problem.

SELECT TOP 3
    hiscore.user_id,
    hiscore.user_name,
    MAX(hiscore.score) AS max_score,
FROM
    hiscore
GROUP BY
    hiscore.user_id, hiscore.user_name
ORDER BY
    max_score DESC

UPDATE: Regarding score sum question

Regarding score sum, I need query that will return this when querying original hiscore table:

user_id   user_name    score
--------------------------------
1          Tom        1000
2          Jim         800
3          Tony        650

And if there are two users with the same score sum, user with better rank is the one with less entries in hiscore table.

  • 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-07T11:31:06+00:00Added an answer on June 7, 2026 at 11:31 am

    Edit: this first query is a lie and won’t work! :), assuming sql 2005+ use the second one

    Just add EntryDate to your order by

    SELECT TOP 3 
        hiscore.user_id, 
        hiscore.user_name, 
        MAX(hiscore.score) AS max_score, 
    FROM 
        hiscore 
    GROUP BY 
        hiscore.user_id, hiscore.user_name 
    ORDER BY 
        max_score DESC, entry_date DESC
    

    Edit: ah I didn’t even see the group by – forget that, hang on a sec!

    This one 😛

    SELECT * FROM (SELECT
        hiscore.user_id,
        hiscore.user_name,
        hiscore.score,
        hiscore.entry_date,
        ROW_NUMBER() OVER (PARTITION BY User_id ORDER BY Score DESC, entry_date) as scoreNo
    FROM 
        hiscore 
    ) as highs WHERE ScoreNo = 1 ORDER BY Score DESC, entry_date
    

    assuming SQL 2005+

    Edit:

    In order to get the best scores ordered by score and then by number of entries the query is a bit simpler:

    SELECT user_id, user_name, SUM(score) as Score from hiscore
    GROUP BY user_id, user_name
    ORDER BY sum(score) DESC, count(score) 
    

    This will give you the scores ordered by the sum of ‘score’ descending, and then ordered by number of entries ascending which should give you what you want

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

Sidebar

Related Questions

I want create object from Canvas3D class(in java) but my Compiler doesn't have this
I want create a project where every user can have his own 'homepage'. So
i want create Dynamic Slideshow in Jquery i'm Write this code var ctx =
say, I have a table TABLE(col1,col2,col3) and, I want create a index INDEX(col1=table.col1+table.col2)
I want create a DataSet class which is basically a list of samples. But
I want create subdomains like this: domain.com/type/city An examples: domain.com/restaurants/new_york domain.com/hotels/new_york domain.com/restaurants/chicago I have
I want create wordpress website into which I want create user management... That means
i want create image animation , i have 50 images with png format now
I want create module which update list of usb devices automatically (not only mass
I want to create a new field (or two) in my table that 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.