Update table equalize where same id but different country
<p>I have a problem creating an SQL statement that would run in a cronjob every few minutes.</p>

<p>I want to equalize one column where <code>ItemCode</code>s (IDs) are the same but each country is different</p>

<p>Table: </p>

<pre><code>+----------+--------+---------+

| ItemCode | OnHand | country |

+----------+--------+---------+

| 08040    | 450    | de      |

+----------+--------+---------+

| 08040    | 000    | hu      |

+----------+--------+---------+

| 08040    | 145    | si      |

+----------+--------+---------+
</code></pre>

<p>I want to take <code>OnHand where country = de</code> and put it in <code>OnHand where country = hu</code>. (for multiple <code>ItemCode</code> - have 7000 of them)</p>

<pre><code>UPDATE sap_items
    ON sap_items.ItemCode = sap_items.ItemCode AND
       sap_items.country='de'
SET sap_items.OnHand = sap_items.OnHand
WHERE sap_items.country='hu'";
</code></pre>

<p>I understand that this is wrong. But i'm not sure how to properly put it. </p>