title: MySQL select count
body: <p>I am trying to count the number of companies that have at least one product from the following query</p>
  
  <pre><code>SELECT count(*)
  FROM company c
  JOIN product p on c.id = product.company_id
  WHERE p.is_deleted = 0
  AND c.is_customer = 1
  AND c.company_type_id = 5
  GROUP by c.id
  </code></pre>
  
  <p>So, this shows me a list of all companies, and the count of products for each company.</p>
  
  <p>What I am trying to achieve is a count of companies from the above result.</p>
  
  <p>This can be achieved as follows:</p>
  
  <pre><code>SELECT count(*)
  FROM ( 
      SELECT count(*)
      FROM company c
      JOIN product p on c.id = product.company_id
      WHERE p.is_deleted = 0
      AND c.is_customer = 1
      and c.company_type_id = 5
      GROUP by c.id) AS t1
  </code></pre>
  
  <p>So, this gives me the correct result, but I am just wondering if there is a more efficient way of doing things.</p>