title: voting system, relational db, sql query
body: <p>I want to design voting system with two tables.</p>
  
  <p>First table contains candidates' index and name.</p>
  
  <p>The other one contains index, voter and candidate's index whom the voter support.</p>
  
  <p>One voter can support multiple candidates.</p>
  
  <p>I want a sql query that shows candidates' name with number of its supporters.</p>
  
  <p>So the result looks like</p>
  
  <p>John 12, Bob 8, David 3...</p>
  
  <pre><code>SELECT `name`, COUNT(table2.voter) AS `count` 
  FROM `table1` 
  LEFT JOIN `table2` 
     ON table1.idx = table2.support 
  ORDER BY COUNT(table2.voter) DESC;
  </code></pre>
  
  <p>The above query gave only one row with total number of voter.</p>
  
  <p>Can anyone give me any hints?</p>