join - Mysql query follow follower system -
i have following tables
followtable
columns userid
followingid
and
usertable
columns userid
username
now find out follows me assuming i'm user 1 run query
select usertable.username, usertable.userid usertable inner join followtable on followtable.userid = usertable.userid followtable.followingid = '1' order followtable.datefollowed desc
so i'm able put in , array echo out in php
the result this
username userid john 2 joe 5
now want find out if i'm following user using same query output table this
username userid followinguser john 2 0 joe 5 1
where 0 means not following user , 1 means following user.
can point me in right direction on how perform query. tried using self join no avail.
select t1.userid,t1.username ,coalesce(t2.followornot, 0) followornot user t1 left join (select f.userid fid,1 followornot follow f f.followingid='youruseridhere' ) t2 on t1.userid=t2.fid
Comments
Post a Comment