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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:57:51+00:00 2026-06-07T02:57:51+00:00

I have a users table with the following data: +—-+————+————–+————–+————–+ | id | name

  • 0

I have a users table with the following data:

+----+------------+--------------+--------------+--------------+
| id | name       | points_game1 | points_game2 | points_game3 |
+----+------------+--------------+--------------+--------------+
|  1 | player 1   |           10 |            0 |            5 |
|  2 | player 2   |            0 |           25 |            0 |
|  3 | player 3   |           30 |            3 |            0 |
|  4 | player 4   |            0 |            0 |           20 |
+----+------------+--------------+--------------+--------------+

I want to be able to show overall ranks, where the ranking is defined as the overall highest score rather than a ranking per game. So in the example above, what query would I use to display this result:

+----+------------+-------+----------------+
| id | name       | score | game           |
+----+------------+-------+----------------+
|  3 | player 3   |    30 | points_game1   |
|  2 | player 2   |    25 | points_game2   |
|  4 | player 4   |    20 | points_game3   |
|  1 | player 1   |    10 | points_game1   |
+----+------------+-------+----------------+
  • 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-07T02:57:52+00:00Added an answer on June 7, 2026 at 2:57 am

    The following query answers your question:

    SELECT 
      id, 
      name, 
      GREATEST(points_game1, points_game2, points_game3) AS score,
      CASE
        WHEN points_game1 = GREATEST(points_game1, points_game2, points_game3) THEN 'points_game1'
        WHEN points_game2 = GREATEST(points_game1, points_game2, points_game3) THEN 'points_game2'
        WHEN points_game3 = GREATEST(points_game1, points_game2, points_game3) THEN 'points_game3'
      END AS game
    FROM
      users
    ORDER BY 
      3 DESC
    

    A bit crude due to repetitiveness of the GREATEST(…) calculation. You may wish to put that in a subquery.

    At any case, make note that this query will not utilize any index on the table since the ORDER BY uses a function over columns — that negates usage of a key in MySQL.

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

Sidebar

Related Questions

Ok, I have the following Users table: id | name | birthday 1 |
I have the following situation. We want an reputation table to evaluate Users And
I have the following table for storing user data: e.g. TABLE: users COLUMNS: ...
I have a table [Users] with the following columns: INT SmallDateTime Bit Bit [UserId],
I have a table with sets of settings for users, it has the following
I have a following SQL table with data ProductList id order productname 79 1
I have a table with the following sample data: id user_id rank date_promoted 1
My table column contains following sample data: /Users/abct2/Library/Application Support/iPhone Simulator/4.3/Applications/FD301781-D39F-469E-A604-8164CC9A4493/Library/Caches/List3-ROHAN TEST1/word_306:24:50.jpg Now, I want
I have the following tables in MySQL: users profile rates In the users table,
I have a table with the following fields: email - name - username -

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.