I have 3 tables on my database :
Users :
id ------- username
1 user1
2 user2
writers
id ------- name
4 writer4
5 writer5
8 writer8
Following :
user_id ----- follow
1 5
1 8
2 5
so, now User1 follows writer5 and writer8 , and user2 follows writer5
I’m login to my app as user1 , when I go to the writers page I get list of all writers in the database ..
I just want to show in front of each writer whether I’m following this writer or not ..
List Writers Page example:
writer4 :follow
writer5 :unfollow (i'm following him now)
writer8 :unfollow (i'm following him now)
writer100 :follow
my question is : Is there a query to get the full list of writers and give me a value=0 if I’m not (as user1) following this writer
any ideas ?
thanks ..
You need to use
CROSS JOINin order for user to get all writers.SQLFiddle Demo