title: Loop update statement in mysql
body: <p>I currently trying to update rows using loop in a table.</p>
  
  <p>I have fields named 'id' and 'visitor_id'. 
  'id' column is auto increment but 'visitor_id' is not. There are already existing data inside the table and both columns look like this.</p>
  
  <pre><code>'id'     'visitor_id'
   1            0
   2            0
   3            0
   4            0
   5            0
  </code></pre>
  
  <p>So what I want is I want these both columns to have the same value. </p>
  
  <pre><code>'id'     'visitor_id'
   1            1
   2            2
   3            3
   4            4
   5            5
  </code></pre>
  
  <p>I try and search on how to loop and update the value but still no luck.This is the code that i try.</p>
  
  <pre><code>DELIMITER $$
  
  DROP PROCEDURE IF EXISTS insert_loop $$
  
  CREATE PROCEDURE insert_loop ()
  BEGIN
      DECLARE i int DEFAULT 1;
      WHILE i &lt;=30 DO
          UPDATE test_db.visitor_visit SET visitor_id=i WHERE id=i;
          SET i = i + 1;
      END WHILE;
  END $$
  
  CALL insert_loop();
  </code></pre>
  
  <p>I will accept any other method that might help my situation. Thanks! :)</p>