title: SELECT INTO with LIMIT
body: <p>If I have a table defined like so: <code>mytable(model char(4), price int);</code> and I'm trying to find the value closest to price given a base price, how would I go about it?</p>
  
  <p>What I have is this:</p>
  
  <pre><code>delimiter //
  CREATE FUNCTION findClosestPrice (value int) returns int
  BEGIN
      DECLARE closestPrice int default -1;
      DECLARE row int default 0;
      DECLARE rows int default 0;
      DECLARE currPrice int default -1;
      select count(*) from mytable into rows;
      SET row=0;
      WHILE row &lt; rows DO
          select price from mytable limit row, 1 into currPrice; &lt;----- this gives an error
          SET row = row + 1;
      END WHILE;
  END//
  </code></pre>
  
  <p>Why is it that I can't have that line?<br>
  How do I go about selecting the price from a current row in a loop and saving it into a variable that I've declared? I thought this would work but it does not.</p>