title: Php Mysql Join two tables with multiple codition and null records
body: <p>I have tried to fetch records from 2 tables but it is not showing required output where my first table is ttreply</p>
  
  <p><a href="https://i.stack.imgur.com/WMG3N.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WMG3N.png" alt="ttreply table"></a></p>
  
  <p>And another table is ttreplycount where count stored as below:</p>
  
  <p><a href="https://i.stack.imgur.com/WIm1E.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WIm1E.png" alt="ttreplycount"></a></p>
  
  <p>I have tried to fetch value but it doesn't fetch records as i want my mysql query as below:</p>
  
  <pre><code>SELECT r.id, r.userid, r.`reply`, coalesce(x.votes,0) as Votes 
  FROM `ttreply` r left join 
  (SELECT sum(votes) as Votes from `ttreplyvotes` )x ON r.`post_id`=2 
  </code></pre>
  
  <p>Which showing me output like this:</p>
  
  <p><a href="https://i.stack.imgur.com/hUS85.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hUS85.png" alt="Output"></a></p>
  
  <p>What i needed is like this:</p>
  
  <pre><code>id  userid    reply                Votes
  2   3       Testing 2nd reply      -2
  3   3       Testing 3nd reply       0
  4   3        rewsf                  0
  </code></pre>
  
  <p>Any help would be helpful.</p>