mysql - Is it possible to count two columns in the same query -
let's have following table structure:
t1 ------------- id // row id userid_follower // user follows member userid_following // other member user
is possible run single query combine both of following:
how many users person following
select count(id) t1 userid_follower = ".$myid." ."
how many users follow person
select count(id) t1 userid_following = ".$myid."
thanks.
in mysql, can use sum()
function on condition, since false condition equal 0
, , true 1 equal 1
:
select sum(userid_follower = $myid) followercount, sum(userid_following = $myid) followingcount t1 userid_follower = $myid or userid_following = $myid
Comments
Post a Comment