Need Select top 10 people SQL

mysql, sql

Solution

You want to use MySQL GROUP BY aggregation funciton

SELECT user_id, COUNT(follow_id) AS total_followers
FROM users 
GROUP BY follow_id 
ORDER BY total_followers LIMIT 10;

Problem

I need SQL query for MySQL to select top 10 people with most followers my table ``` id | user_id | follow_id 1 3 6 2 3 7 3 4 6 4 5 6 5 7 3 6 9 7 ``` From example user with id 6 have 3 time followed , 7->2 and 3->1, so TOP 10 will be user with id 6,7,3 ...

Original source