title: MySQL - JOIN only if a row exists from the left table
body: <p>Here is MySQL:</p>
  
  <pre><code>SELECT  a.id,
          a.name,
          a.n,
          a.r,
          a.pot,
          a.ticket_price,
          a.starting_tickets,
          a.started,
          a.end,
          COUNT(b.id) tickets_bought 
  FROM current_lotteries a
     JOIN lottery_tickets b ON b.lid=a.id
  WHERE a.cid=1 
  ORDER BY started DESC LIMIT 1    
  </code></pre>
  
  <p>In the search, if there is no row from <code>a</code> but there are rows in <code>b</code> (i.e <code>COUNT(b.id)</code> is not <code>NULL</code>) then this query returns a row with <code>NULL</code> values for <code>a</code> fields and whatever the value of <code>COUNT(b.id)</code> as <code>tickets_bought</code>. How do I modify this query so it does not return a row (<code>num_rows = 0</code>) if there is no result in table <code>a</code>?</p>
  
  <p>A Snap.  </p>
  
  <p><img src="https://i.stack.imgur.com/Gt3xp.jpg" alt="query"></p>