title: Mysql query count total from other table
body: <p>Table jenis_usaha  </p>
  
  <pre><code>ID JENIS_USAHA  
  1 Laundry  
  2 Restauran
  </code></pre>
  
  <p>Table waralaba  </p>
  
  <pre><code>ID ID_JENIS_USAHA  
  1 1  
  2 2
  </code></pre>
  
  <p>Table perusahaan  </p>
  
  <pre><code>ID NAME ID_WARALABA  
  1 A 1  
  2 B 2  
  3 C 1
  4 D 1
  </code></pre>
  
  <p>Table outlet  </p>
  
  <pre><code>ID ID_PERUSAHAAN  
  1 1  
  2 1  
  3 2  
  4 2  
  5 1  
  6 1  
  7 1  
  8 1  
  9 1
  </code></pre>
  
  <p>The result that I want is like this</p>
  
  <pre><code>ID JENIS_USAHA TOTAL_PERUSAHAAN TOTAL_OUTLET  
  1  Laundry          3                7   
  2  Restauran        1                2
  </code></pre>
  
  <p>I have this mysql query</p>
  
  <pre><code>SELECT  ju.ID, 
          ju.JENIS_USAHA,
          COUNT(p.ID) AS TOTAL_PEMBERI,
                  (SELECT count(o.ID)
                      FROM outlet o 
                      WHERE p.ID = o.ID_PERUSAHAAN
                          AND w.ID = p.ID_WARALABA
                          AND ju.ID = w.ID_JENIS_USAHA
                      ) AS TOTAL_OUTLET
  FROM jenis_usaha ju
              LEFT JOIN waralaba w ON w.ID_JENIS_USAHA = ju.ID
              LEFT JOIN perusahaan p ON p.ID_WARALABA = w.ID           
  GROUP BY ju.ID  
  </code></pre>
  
  <p>I've got no error BUT a wrong result for TOTAL_OUTLET. Could you please show me the right query for this? thanks</p>