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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:42:10+00:00 2026-06-16T11:42:10+00:00

A couple months ago I asked a question about something similiar to this, received

  • 0

A couple months ago I asked a question about something similiar to this, received some help and thought I had the answer. 3 months later I am seeing this didnt work 100% so I need some more help but I can ask the question better now that I understand more.

I have a mysql table with id, userid, rounds, reps, exerciseid

I need to pull a users highest round specific to the exercise I am pulling for. So if the exerciseid was 8 I would need the users top round for that exerciseid but if the user has the same rounds more than once, which happens a lot, then I need to sort that by the reps to give me a true highest performance. Now, after obtaining those results I need to then sort this data set by rounds,reps so if multiple unique users have the same rounds that is then ordered by reps.

Can this be done with pure mysql or am I better off pulling the data and sorting everything with PHP?

SELECT
  max(l.rounds) as rounds,
  l.reps,l.userid
from leaderboard l
where l.exerciseid = 8 
group by l.userid 
order by 
  rounds desc,
  reps desc 

example of structure
First this is a smaple set

userid  exerciseid  rounds  reps
--     --     --
1    8  23  10
1    8  23  15
1    8  20  10
2    8  28  19
2    8  15  12
3    8  40  29


results I want

userid  exerciseid  rounds  reps
--     --     --
3    8  40  29
2    8  28  19
1    8  23  15
  • 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-16T11:42:11+00:00Added an answer on June 16, 2026 at 11:42 am

    If I understand this correctly, you want to first group by userid and rounds to get the maxreps on a round. Then you want to select the max rounds from this.

    Here is one way to express this in MySQL:

    select userid, rounds, maxreps
    from (SELECT userid, l.rounds, MAX(l.reps) as maxreps
          from leaderboard l
          where l.exerciseid = 8 
          group by l.userid, l.rounds
         ) ur
    where exists (select 1 from leaderboard lb where ur.userid = lb.userid and lb.exerciseid = 8 group by lb.userid having max(rounds) = ur.rounds))
    order by rounds desc, maxreps desc 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is the opposite of a question I asked a couple of months ago.
A couple of weeks ago I asked a question and I got totally slammed
A couple months ago I heard about a new Visual Studio feature for compiling
I ran acrossed this a couple months ago and did not save the link
A couple of months ago I read a blog post about a ruby gem
Made this 2D water demo a couple of months ago( http://nauful.com/Qasim/Pani.html ), and it's
I have a huge disgusting stored procedure that wasn't slow a couple months ago,
Couple of months ago, we revamped our web site. We adopted totally new site
A couple of months ago I was doing Javascript programming on the Facebook platform,
I've dived into the GWT world a couple of months ago and find 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.