title: Mysql copy data from one table to another with on duplicate key update not working, repeat data
body: <p>this is my mysql data to copy</p>
  
  <p>table 'questions'</p>
  
  <pre><code>id|question_text  |priority|quiz_id|
  1 |&lt;p&gt;Letter D&lt;/p&gt;|   1    |    1  |
  2 |&lt;p&gt;Letter B&lt;/p&gt;|   2    |    1  |
  3 |&lt;p&gt;Letter C&lt;/p&gt;|   3    |    1  |
  </code></pre>
  
  <p>Then this is my new table I already have the two question
  table 'testbank_question'</p>
  
  <pre><code>id|question_id|question_text  |priority|quiz_id|
  89|        1  |&lt;p&gt;Letter A&lt;/p&gt;|   1    |    1  |
  90|        2  |&lt;p&gt;Letter B&lt;/p&gt;|   2    |    1  |
  </code></pre>
  
  <p>when I update, I want the result looks like this in my new table
  table 'testbank_question'</p>
  
  <pre><code>id |question_id|question_text  |priority|quiz_id|
  89 |        1  |&lt;p&gt;Letter D&lt;/p&gt;|   1    |   1  |
  90 |        2  |&lt;p&gt;Letter B&lt;/p&gt;|   2    |   1  |
  150|        3  |&lt;p&gt;Letter C&lt;/p&gt;|   3    |   1  |
  </code></pre>
  
  <p>--table 'questions' create statemate</p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS `questions` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `question_text` varchar(3800) DEFAULT NULL,
    `question_type_id` int(11) NOT NULL,
    `priority` int(11) NOT NULL,
    `quiz_id` int(11) NOT NULL,
    `point` decimal(18,0) NOT NULL,
    `added_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `parent_id` int(11) NOT NULL,
    `question_total` decimal(18,0) DEFAULT NULL,
    `check_total` int(11) DEFAULT NULL,
    `header_text` varchar(1500) CHARACTER SET utf8 DEFAULT NULL,
    `footer_text` varchar(1500) CHARACTER SET utf8 DEFAULT NULL,
    `question_text_eng` varchar(1800) CHARACTER SET utf8 DEFAULT NULL,
    `help_image` varchar(550) CHARACTER SET utf8 DEFAULT NULL,
    PRIMARY KEY (`id`),
    KEY `quiz_id` (`quiz_id`)
  ) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;
  
  
  INSERT INTO `questions` (`id`, `question_text`, `question_type_id`, `priority`, `quiz_id`, `point`, `added_date`, `parent_id`, `question_total`, `check_total`, `header_text`, `footer_text`, `question_text_eng`, `help_image`) VALUES
  (1, '&lt;p&gt;\r\n    Letter A&lt;/p&gt;', 1, 1, 1, 1, '2013-03-06 09:12:58', 0, NULL, NULL, '', '', NULL, NULL),
  (2, '&lt;p&gt;\r\n    Letter B&lt;/p&gt;', 1, 2, 1, 1, '2013-03-06 09:13:21', 0, NULL, NULL, '', '', NULL, NULL),
  (3, '&lt;p&gt;\r\n    letter C&lt;/p&gt;', 1, 3, 1, 1, '2013-03-06 13:43:48', 0, NULL, NULL, '', '', NULL, NULL);
  
  ALTER TABLE `questions`
    ADD CONSTRAINT `questions_ibfk_1` FOREIGN KEY (`quiz_id`) REFERENCES `quizzes` (`id`) ON DELETE CASCADE;
  </code></pre>
  
  <p>--</p>
  
  <h2>-- Table structure for table <code>testbank_question</code></h2>
  
  <pre><code>CREATE TABLE IF NOT EXISTS `testbank_question` (
    ` id` int(100) NOT NULL AUTO_INCREMENT,
    `question_id` int(100) NOT NULL,
    `question_text` varchar(3800) NOT NULL,
    `question_type_id` int(11) NOT NULL,
    `priority` int(11) NOT NULL,
    `quiz_id` int(11) NOT NULL,
    `point` decimal(18,0) NOT NULL,
    `added_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `parent_id` int(11) NOT NULL,
    `question_total` decimal(18,0) NOT NULL,
    `check_total` int(11) NOT NULL,
    `header_text` varchar(1500) NOT NULL,
    `footer_text` varchar(1500) NOT NULL,
    `question_text_eng` varchar(1800) NOT NULL,
    `help_image` varchar(550) NOT NULL,
    PRIMARY KEY (` id`),
    KEY `quiz_id` (`quiz_id`),
    KEY `question_id` (`question_id`)
  ) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=176 ;
  </code></pre>
  
  <p>--</p>
  
  <h2>-- Dumping data for table <code>testbank_question</code></h2>
  
  <pre><code>INSERT INTO `testbank_question` (` id`, `question_id`, `question_text`, `question_type_id`, `priority`, `quiz_id`, `point`, `added_date`, `parent_id`, `question_total`, `check_total`, `header_text`, `footer_text`, `question_text_eng`, `help_image`) VALUES
  (89, 1, '&lt;p&gt;\r\n    Letter A&lt;/p&gt;', 1, 1, 1, 1, '2013-03-06 09:12:58', 0, 0, 0, '', '', '', ''),
  (90, 2, '&lt;p&gt;\r\n    Letter B&lt;/p&gt;', 1, 2, 1, 1, '2013-03-06 09:13:21', 0, 0, 0, '', '', '', '');
  </code></pre>
  
  <p>--</p>
  
  <h2>-- Constraints for table <code>testbank_question</code></h2>
  
  <pre><code>ALTER TABLE `testbank_question`
    ADD CONSTRAINT `testbank_question_ibfk_1` FOREIGN KEY (`quiz_id`) REFERENCES `testbank_quizzes` (`copy_id`) ON DELETE CASCADE;
  </code></pre>
  
  <p>In my new table,the field question_id is equal to the id of the data that I want to copy.
  this is my code in Php</p>
  
  <pre><code>INSERT INTO testbank_question
          (question_id,
           quiz_id,
           question_text,
           question_type_id,
           priority,point,
           added_date,
           parent_id,
           question_total,
           check_total,
           header_text,
           footer_text,
           question_text_eng,
           help_image) 
    SELECT         id,
           quiz_id,
           question_text,
           question_type_id,
           priority,
           point,
           added_date,
           parent_id,
           question_total,
           check_total,
           header_text,
           footer_text
           ,question_text_eng,
           help_image 
    FROM questions WHERE
          questions.quiz_id='1' ON DUPLICATE KEY UPDATE
       testbank_question.question_id = VALUES(testbank_question.question_id)
  </code></pre>