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:

  1. how many users person following

    select count(id) t1 userid_follower = ".$myid." ."

  2. 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

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -