I just can not implement such a request: you must output the id of the user who has the maximum number of friends.
There is such a table:
user_one user_two type 5 6 1 6 5 1 12 6 1 7 34 1 34 7 1 12 7 2 34 7 2 When I do this, everything is OK:
SELECT COUNT(*) AS counted FROM `friends` WHERE `type`='1' AND `user_two`='6' OR `type`='1' AND `user_one`='6' But I want to make sure that all records for individual users are counted and their maximum number is displayed. That is, so that I get the user id (it can be user_one and user_two , that is, with these fields, the difference is that they show who sent the request) whose type=1 . I hope clearly explained, thanks in advance!
friendsWHEREtype= '1' GROUP BYuser_one) as counts But it doesn't work - paskalnikitaselect user,count(1) from (select user_one as user from tab union all select user_two from tab) X order by count(1) desc limit 1- Mike