MySQL Forums
Forum List  »  InnoDB

Re: query by first occurrence in group
Posted by: Peter Brawley
Date: May 22, 2019 01:24PM

You want the "first" row, but without a defined order that's entirely meaningless. Supposing you want the smallest matriculate value per largest number value per sector, that would be ...

select t.sector, n.maxnum, min(t.matriculate) mat
from tbl t
join (
  select sector, max(number) as maxnum
  from tbl
  group by sector
) n on t.sector=n.sector && t.number=n.maxnum
group by sector, number;

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: query by first occurrence in group
82
May 22, 2019 01:24PM


Sorry, only registered users may post in this forum.

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.