I think the answer missed the case when A send B a friend request, and B send A a friend request, and both requests got approved. In this case, A or B really just gained one friend. But the answer seems to count this case twice.
Isn't union (remove duplicates) should be used instead of union all?
select id1 as id, count(id2) as num from (select requester_id as id1, accepter_id as id2 from request_accepted union select accepter_id as id1, requester_id as id2 from request_accepted) tmp1 group by id1 order by num desc limit 1
@Fangyyfrank I agree. The solution is wrong. Hope they can fix this soon.