title: How to copy data from 1 table to another with different structure
body: <p>I have a table with the structure </p>
  
  <pre><code>CREATE TABLE `old_reminder` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `applicant_id` int(11) NOT NULL,
    `date` datetime NOT NULL,
    `type` enum('payment_15_min','payment_1_day','payment_3_day') NOT NULL DEFAULT 'payment_15_min',
    PRIMARY KEY (`id`)
  )
  </code></pre>
  
  <p>and I want to migrate its data to another table with the structure </p>
  
  <pre><code>CREATE TABLE `new_reminders` (
    `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
    `user_id` int(11) DEFAULT NULL,
    `payment_reminder_1_count` int(11) DEFAULT NULL,
    `payment_reminder_1_date` datetime DEFAULT NULL,
    PRIMARY KEY (`id`)
  )
  </code></pre>
  
  <p>basically multiple rows for each <code>user_id</code> will be converted into 1 row with all the enum values as columns.
  I have tried the following but it is updating only 1 row</p>
  
  <pre><code>UPDATE reminders 
      INNER JOIN old_reminder AS `old`
      ON user_id = old.applicant_id
      SET new_reminder_1_date = IF(old.type = 'payment_15_min' OR old.type = 'payment_1_day' OR old.type = 'payment_3_day', old.date, '2018-01-01 00:00:00'),
      payment_reminder_1_count = IF(old.type = 'payment_15_min' OR old.type = 'payment_1_day' OR old.type = 'payment_3_day',
      CASE
      WHEN old.type = 'payment_15_min' THEN 1
      WHEN old.type = 'payment_1_day' THEN payment_reminder_1_count + 1
      WHEN old.type = 'payment_3_day' THEN payment_reminder_1_count + 1 END, 0)
      WHERE applicant_id = 123;
  </code></pre>