title: How to code a simple stepped counter based on a select sentence
body: <p>I am trying to create a store procedure that returns as many rows as numbers in a sequence [0..max], incrementing values with a given step. The same result we would expect from a for-loop with step.
  I am having a hard time trying to replicate this behaviour on a SQL select basis.</p>
  
  <p>This is my first MySQL approach, returning no rows.
  The expected output should be</p>
  
  <pre><code>10
  20
  30
  ...
  1000
  </code></pre>
  
  <p>Any idea of what's going wrong here?</p>
  
  <pre><code>delimiter $$
  
  create procedure counter (
    _step int,
    _max int
  )
  begin
    select 
      @x := @x + _step as xcount
    from 
      (select @x := 0) ts
    where
      @x &lt;= _max;
  end;
  $$
  
  call counter(10, 1000);
  </code></pre>
  
  <p>A DBFiddle also here 
  <a href="https://www.db-fiddle.com/f/wtwhT7U4Edu6d3t6gwqAJ5/1" rel="nofollow noreferrer">https://www.db-fiddle.com/f/wtwhT7U4Edu6d3t6gwqAJ5/1</a></p>
  
  <h2>Solution</h2>
  
  <p>@Straberry suggestion leads to the following simpler solution, available in MySQL v8. Unfortunately, DBFiddle fails to reproduce the result. You have to try in a local MySQL v8 server.</p>
  
  <pre><code>with recursive cte (n) as (
    select 10
    union all
    select n + 10 from cte where n &lt; 500
  ) select * from cte;
  </code></pre>
  
  <p>More examples and counters in
  <a href="https://dev.mysql.com/doc/refman/8.0/en/with.html#common-table-expressions-recursive-examples" rel="nofollow noreferrer">https://dev.mysql.com/doc/refman/8.0/en/with.html#common-table-expressions-recursive-examples</a></p>