title: mysql count number of votes in votes table
body: <p>I have 3 tables named <code>election_cand</code>, <code>candidate</code> and <code>votes</code>:</p>
  
  <p><code>election_cand</code> table:</p>
  
  <pre><code>ele_can_id | election_id | candidate_id
  </code></pre>
  
  <p><code>candidate</code> table:</p>
  
  <pre><code>id | canname | canadd | canphone | canmail | candes | canphoto
  </code></pre>
  
  <p><code>votes</code> table:</p>
  
  <pre><code>voteid | candidateid | voterid | electionid
  </code></pre>
  
  <p>my tables with data are:</p>
  
  <p><a href="https://i.stack.imgur.com/ASkUx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ASkUx.png" alt="Screenshot 1"></a></p>
  
  <p>I want the desired result as </p>
  
  <p><a href="https://i.stack.imgur.com/XwBRz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XwBRz.png" alt="Screenshot 2"></a></p>
  
  <p>I write the mysql query as:</p>
  
  <pre><code>SELECT a.*,b.*,c.*, count(voteid) AS numrows
  FROM election_cand a
  left join votes b on a.election_id=b.electionid
  left join candidate c on a.candidate_id=c.id
  where a.election_id='$get_ele_id' group by a.candidate_id
  </code></pre>