title: Mysql join query for showing friends posts with viewstatus!=public
body: <p>I have three table <strong>tbl_user, tbl_posts, tbl_friends</strong></p>
  
  <p><strong>tbl_user</strong> stores all the user datas.</p>
  
  <p><strong>tbl_friends</strong> stores which user are friends with other.</p>
  
  <p><strong><code>tbl_posts</code></strong>, where the users posts are stored. <strong><code>userid</code></strong> is the field where all the users id are stored. <strong><code>p_viewstatus</code></strong> field stores the <strong>view status</strong> of the posts. if the <strong>view status</strong> of the <strong>my friends posts</strong> is <strong>only by me</strong> then that posts should not shown to other users</p>
  
  <p>If sam have a post with id=40 in <strong><code>tbl_posts</code></strong>. The <strong><code>p_viewstatus</code></strong> of the post is <strong>only by me</strong> then that post must only be visible to sam only.</p>
  
  <p>If sam have another post with id=41 and <strong><code>p_viewstatus</code>!='only by me'</strong> this post must <strong>visible to all users who are sam's friend</strong></p>
  
  <p>Tried the following query but don't know how to relate the <strong>p_viewstatus</strong></p>
  
  <p><strong>Note: I want to fetch all of my posts and my friends posts from **<code>tbl_posts</code></strong> except the <code>p_viewstatus</code> of my friends posts no equal to 'only by me'**</p>
  
  <pre><code>SELECT * FROM `tbl_posts` as p,`tbl_friends` as f WHERE p.`userid`=f.`userid` and p.`userid`=23
  </code></pre>
  
  <p>Thanks in advance.</p>
  
  <p><img src="https://i.stack.imgur.com/32474.jpg" alt="enter image description here"></p>
  
  <p><img src="https://i.stack.imgur.com/xgTP8.jpg" alt="enter image description here"></p>
  
  <p><img src="https://i.stack.imgur.com/gG7Z9.jpg" alt="enter image description here"></p>
  
  <p><strong>BELOW SCREENSHOT SHOWS THE TABLE CONTENTS AFTER JOIN QUERY.</strong>
  <img src="https://i.stack.imgur.com/su5un.jpg" alt="enter image description here"></p>