MySQL Forums
Forum List  »  Newbie

Re: Select row with highest "pass" number, where user ID is the same in each row
Posted by: Peter Brawley
Date: August 25, 2014 03:01PM

Ok, no ties, then it's a two-step: an inner subquery to find max(pass) per user, and an outer query to find the matching points per user ...

select p.usr_id, s.maxpass, p.points
from pass_results p
join (
  select usr_id,max(pass) as maxpass
  from pass_results
  group by usr_id
) s using(usr_id)
where p.pass=s.maxpass;

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.