I have 2 mysql tables one called 'users' and another called 'connections'
Table users have info about users and has 3 rows:
mikha
guy
maricela
Table connections has the connections between users like twitter (mikha following maricela and maricela following mikha for example)
Connections has the following rows:
username1 | username2
--------------------------
guy | maricela
mikha | guy
mikha | maricela
I want to get info about 'mikha' including the number of people he following and the number who follow him back.
I use the following query:
SELECT *, COUNT(DISTINCT connections.username1) AS count_following,
COUNT(DISTINCT connections.username2) AS count_followers
FROM users LEFT JOIN connections on connections.username1 = 'mikha' OR
connections.username2 = 'mikha' WHERE users.username = 'mikha'
Expected:
count_following = 2 (as mikha is following guy and maricela)
count_followers = 0 (no one following mikha yet)
Actual:
count_following = 2
count_followers = 1
Thanks Regards Michael