title: MySQL Loop Variable in a Query
body: <p>I want to use the loop index "i" in the result of my select statement in order to insert it into another table. Is is like:</p>
  
  <pre><code>set i=0;
  while i&lt;25 do
  
      insert into a (x,y,z)
      select a,b,i
      from table1;
  
      set i= i+1;
  end while;
  </code></pre>
  
  <p>What is the way to do it?</p>