In mysql I am wanting to count the number of followers each user has and the table doesn't have related columns. I would like the name and the total followers to display, but each person is displaying as having 1 follower which isn't the expected outcome.
Insert Scripts
insert into user (email, password, first_name, last_name) values ('rclunan0@reference.com', 'E7WC5qpzFPA1', 'Richmound', 'Clunan');
insert into user (email, password, first_name, last_name) values ('hturn1@tiny.cc', 'MjEUC4', 'Herculie', 'Turn');
insert into user (email, password, first_name, last_name) values ('wrogier2@intel.com', 'r7BYgEI0', 'Wenonah', 'Rogier');
insert into user (email, password, first_name, last_name) values ('aavramovsky3@woothemes.com', 'FMiUgn66amxW', 'Aleta', 'Avramovsky');
insert into user (email, password, first_name, last_name) values ('tdoldon4@xing.com', '2UzOXfYyK', 'Teddi', 'Doldon');
insert into user (email, password, first_name, last_name) values ('haddyman5@4shared.com', '7GVGQDIBt8fa', 'Hinda', 'Addyman');
insert into user (email, password, first_name, last_name) values ('rgolsby6@slate.com', 'KqklbW', 'Randi', 'Golsby');
insert into user (email, password, first_name, last_name) values ('mhulson7@amazon.co.uk', 'dwUaaMlu', 'Mason', 'Hulson');
insert into user (email, password, first_name, last_name) values ('kdorkins8@t.co', 'qDegvwr8A1n', 'Kareem', 'Dorkins');
insert into user (email, password, first_name, last_name) values ('jpenketh9@topsy.com', 'WucCOGk8', 'Jillane', 'Penketh');
INSERT INTO `following` ( following_id, follower_id)
VALUES (1, 2), (2, 1), (1, 3), (3, 1), (1, 4), (4, 1), (1, 5), (5, 1), (1, 6), (1, 7), (1, 8), (1, 9), (1, 10);
Following
- id
- following_id
- followers_id
User
- id
- first_name
- last_name
- username
the query that I have written
select first_name, count(follower_id)
from `following`
join `user`
on `user`.id = `following`.id
group by first_name
order by count(follower_id) desc;
Expected output:
user|followers
Richmound | 9
Herculie | 1
Wenonah | 1
Aleta | 1
Teddi | 1
Hinda | 0
Randi | 0
Mason | 0
Kareem | 0
Jillane | 0