title: PHP MySQL double inner join
body: <p>I have three tables:</p>
  
  <p><strong>posts</strong></p>
  
  <ul>
  <li>id</li>
  <li>post_id</li>
  <li>user_id</li>
  </ul>
  
  <p><strong>comments</strong></p>
  
  <ul>
  <li>id</li>
  <li>post_id</li>
  <li>comment_id</li>
  <li>user_id</li>
  <li>deleted</li>
  </ul>
  
  <p><strong>replies</strong></p>
  
  <ul>
  <li>id</li>
  <li>post_id</li>
  <li>reply_id</li>
  <li>user_id</li>
  <li>deleted</li>
  </ul>
  
  <p>I am trying to get all comments and replies from each <code>post.post_id</code> with <code>post.user_id=x</code>.</p>
  
  <p>I tried:</p>
  
  <pre><code>    SELECT *
      FROM posts AS p
      INNER JOIN comments as c
      ON c.comment_id=p.post_id
      INNER JOIN replies as r
      ON r.reply_id=p.post_id
      WHERE
      p.user_id='x'
  </code></pre>
  
  <p>which returns 0...</p>
  
  <hr>
  
  <p>The solution was</p>
  
  <pre><code>SELECT *
  FROM POSTS A
  LEFT JOIN COMMENTS B ON A.POST_ID=B.COMMENT_ID
  LEFT JOIN REPLIES C ON A.POST_ID=C.REPLY_ID
  WHERE A.USER_ID='X'
  </code></pre>
  
  <p>So if I add a deleted column on the <em>comments</em> and <em>replies</em> tables, how can I check if the comment or reply I am getting is not deleted?</p>
  
  <p>I tried adding after <code>A.USER_ID='X' &amp;&amp; B.deleted='0' &amp;&amp; C.deleted='0'</code></p>
  
  <p>But it returns 0.</p>