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

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

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.