title: sql select count of multiple relationships with left join
body: <p>I have  a table for "branches", "orders" and "products. Each order and product are connected to a branch with branch_id. I need an sql statement to get a list of all branches with a field for how many orders and a field for how many products.  </p>
  
  <p>This works:  </p>
  
  <p><code>SELECT  b.*, COUNT(o.id) AS orderCount FROM branches b
              LEFT JOIN orders o ON (o.branch_id = b.id) GROUP BY b.id</code></p>
  
  <p>but it only gets the amount of orders, not products.
  If I change it to add amount of products, the amounts are wrong because it's getting amount of orders * amount of products.  </p>
  
  <p>How can I get the amount of both the orders and the products in the same SQL statement?</p>