I have three table tbl_user, tbl_posts, tbl_friends
tbl_user stores all the user datas.
tbl_friends stores which user are friends with other.
If sam have a post with id=40 in
If sam have another post with id=41 and
Tried the following query but don't know how to relate the p_viewstatus
Note: I want to fetch all of my posts and my friends posts from **
SELECT * FROM `tbl_posts` as p,`tbl_friends` as f WHERE p.`userid`=f.`userid` and p.`userid`=23
Here's how your query should look like:
SELECT * FROM `tbl_posts` as p WHERE p.`userid`=23 OR (p.`userid` IN (SELECT `friendsid` `FROM tblfriends` WHERE `userid`=23) AND p.`p_viewstatus`<>'only by me')
First you select the data from the table you need. After that you filter it with the user id and the ids of the friends of the user and you also tell it that you only want the posts that are not viewable only by me.