title: How to get multiple counts in one sql query across multiple tables
body: <p>I have 2 tables</p>
  
  <p>Company &amp; products</p>
  
  <p>I need to get 2 counts. One is the total count of products and the secondly count of products for sale_flg=1       </p>
  
  <p>This SQL does not seem to work..Tried several other ways..not able to get the expected results</p>
  
  <pre><code>SELECT A.COMPANY_NAME, COUNT(B.PRODUCT_ID) AS TOTAL_COUNT_OF_PRODUCTS, 
         (CASE WHEN B.SALEFLG =1 THEN 1 END) AS COUNT_OF_SALES
  FROM COMPANY A LEFT JOIN
       PRODUCT B
       ON B.COMPANY_ID = A.COMPANY_ID
  GROUP BY A.COMPANY_NAME 
  </code></pre>