title: SQL count and join from multiple tables
body: <p>There is a product table which contains all the product details. A product can be nominated to the popular table from where different people can vote on it. i need to count only the votes of registered users. Currently it is counting all the votes that a particular product has. How do i overcome this problem? i have pasted my sql code below:</p>
  
  <pre><code>SELECT popular.name, popular.product_id, product.text, product.author, count(        vote.product_id ) AS votes
  FROM popular
  LEFT JOIN product ON ( product.id = popular.product_id )
  LEFT JOIN vote ON ( vote.product_id = popular.product_id )
  where popular.hidden = '1' and
  popular.name in (select registered.name from registered 
  where registered.course_id='".$course_id."' and 
  registered.section = '".$section."' and 
  registered.term = '".$term."')
  GROUP BY popular.product_id
  ORDER BY votes DESC Limit 10
  </code></pre>