title: INSERT INTO ... SELECT ... ON DUPLICATE KEY
body: <p>I have a table like this:</p>
  
  <pre><code> CREATE TABLE `UserTmp` (
  `user_id` bigint(20) unsigned NOT NULL,
  `nb_invit` bigint(20) unsigned DEFAULT '0',
  `nb_share` bigint(20) unsigned DEFAULT '0',
  `nb_sent` bigint(20) unsigned DEFAULT '0',
  `total` bigint(20) unsigned DEFAULT '0',
  PRIMARY KEY (`user_id`)
  ) ENGINE=MyISAM DEFAULT CHARSET=utf8
  </code></pre>
  
  <p>And i want to execute 3 queries like this (one per table in order to have nb_share, nb_invit and nb_sent) : </p>
  
  <pre><code>INSERT INTO UserTmp (user_id, nb_share)
    select user_id, count(share_date) as 'nb_share' 
    from Share 
    where share_date between '2012-05-21 00:00:00' and '2012-05-28 00:00:00'
  ON DUPLICATE KEY UPDATE nb_share=VALUES(nb_share);
  </code></pre>
  
  <p>with the nb_share field is equals to the number of share of the curent user which exists in table and require an UPDATE</p>
  
  <p>The goal is to have the list of users with them numbers of actions and a total field which is the sum of actions done by an user.</p>
  
  <p>VALUES(nb_share) seams to give to me the total of nb_share by all users and not by the current user.</p>
  
  <p>Have you an idea to solve this?</p>
  
  <p>Thanks</p>