title: UNION ALL LEFT JOIN and SUM returns incorrect value
body: <p>I'm trying to get the inventory amounts of each warehouse on the basis of the inventory code, but the total amounts are returned incorrectly</p>
  
  <p>can you help me find my mistake?</p>
  
  <p>Products</p>
  
  <pre><code>+----------+-------------+------------+
  | barkod   | stokkodu    |  stokadi   |
  +----------+-------------+------------+
  | 10057    | U-56544547  |   Çocuk    |
  | 10312    | U-56548672  |   Gömlek   |
  | 14124    | U-56144681  |   Çanta    |
  | 18137    | U-56511551  |   Cüzdan   |
  | 17859    | U-16511551  |   Gözlük   |
  | 10112    | U-56544672  |   Gömlek   |
  | 10124    | U-56544681  |   Çanta    |
  | 10137    | U-56545551  |   Cüzdan   |
  +----------+-------------+------------+
  </code></pre>
  
  <p>Warehouse 1</p>
  
  <pre><code>+----------+-------------+------+
  | barkod   | stokkodu    | adet |
  +----------+-------------+------+
  | 10111    | U-56544664  |   27 |
  | 10112    | U-56544672  |  141 |
  | 10124    | U-56544681  |   84 |
  | 10137    | U-56545551  |  254 |
  +----------+-------------+------+
  </code></pre>
  
  <p>Warehouse 2</p>
  
  <pre><code>+----------+-------------+------+
  | barkod   | stokkodu    | adet |
  +----------+-------------+------+
  | 10009    | Unknown     |   61 |
  | 10112    | U-56544672  |  131 |
  | 10124    | U-56544681  |   85 |
  | 10137    | U-56545551  |  254 |
  +----------+-------------+------+
  </code></pre>
  
  <p>I tried</p>
  
  <pre><code>SELECT 
     u.stokkodu, 
     products.stokadi,
     SUM(b.adet) AS stokadet,
     SUM(c.adet) AS sayimadet
     FROM (
        SELECT stokkodu FROM wh1 
        UNION ALL
        SELECT stokkodu FROM wh2 WHERE onay = 1 
     ) u   
     LEFT JOIN (
         SELECT 
            stokkodu, 
            adet 
         FROM wh1 
         GROUP BY stokkodu
     ) b ON u.stokkodu = b.stokkodu
     LEFT JOIN (
         SELECT 
            stokkodu, 
            adet 
         FROM wh2 
         WHERE onay = 1 
         GROUP BY stokkodu
     ) c ON u.stokkodu = c.stokkodu
     LEFT JOIN products ON u.stokkodu = products.stokkodu
  GROUP BY u.stokkodu
  </code></pre>
  
  <p>wh1 and wh2 may not have the same products</p>
  
  <p>I desired</p>
  
  <pre><code>+----------+-------------+------------+----------+-----------+
  | barkod   | stokkodu    |  stokadi   | stokadet | sayimadet |
  +----------+-------------+------------+----------+-----------+
  | 10111    | U-56544664  |  Gömlek    |     27   |     0     |
  | 10112    | U-56544672  |  Gözlük    |     141  |     131   |
  | 10124    | U-56544681  |  Ayakkabı  |     84   |     85    |
  | 10137    | U-56545551  |  Çanta     |     254  |     254   |
  | 10009    | Unknown     |  Unknown   |     0    |     61    |
  +----------+-------------+------------+----------+-----------+
  </code></pre>
  
  <p><strong>Thank you</strong></p>