title: mySQL LEFT JOIN and COUNT number of occurrences in right hand table
body: <p>The following mySQL query returns a row structure that provides all rows from the Tickets Table and any matching information from the Sales Table.</p>
  
  <pre><code>SELECT tickets.*, sales.ID AS tcount 
  FROM tickets LEFT JOIN sales ON tickets.ID = sales.ticket_ID
  </code></pre>
  
  <p>However All we want to do is count the number of existing Rows from the right table for each ticket in order to track stock.</p>
  
  <p>I thought this would do it, but although it counts the number of tickets correctly it only returns one row from the ticket table and counts all sales in the column tcount.</p>
  
  <pre><code>SELECT tickets.*, 
  COUNT(sales.ID) AS tcount 
  FROM tickets LEFT JOIN sales ON tickets.ID = sales.ticket_ID
  </code></pre>