Let’s say I have the following table structure:
t1
-------------
id // row id
userID_follower // this user is a follows another member
userID_following // other member that this user
Is it possible to run a single query to combine both of the following:
-
how many users this person is following
select COUNT(id) from t1 WHERE userID_follower = “.$myID.”
.” -
how many users follow this person
select COUNT(id) from t1 WHERE userID_following = “.$myID.”
Thanks.
In MySql, You can use the
SUM()function over a condition, since a false condition will equal to0, and a true one will equal to1: