- Basic Join > sub queries in having
select h.hacker_id, h.name, count(c.challenge_id) cnt
from hackers h
left join challenges c
on h.hacker_id = c.hacker_id
group by h.hacker_id, h.name
having cnt = (select count(cc.challenge_id) from challenges cc group by cc.hacker_id order by count(cc.challenge_id) desc limit 1)
or cnt in (select t.cnt
from (select ccc.hacker_id id, count(ccc.challenge_id) cnt
from challenges ccc
group by ccc.hacker_id) t
group by t.cnt
having count(t.id) = 1)
order by cnt desc, h.hacker_id asc